insert rows in vba based on two criteria

trgrove11

New Member
Joined
Mar 8, 2014
Messages
3
hi all,

i'm just a beginner with vba so please give me an explanation for the answer below. As a note, i'm looking to solve this with vba as this is part of a longer piece of code. I'm working with a table like this:

[TABLE="width: 500"]
<tbody>[TR]
[TD]Absolute Return[/TD]
[TD]Description[/TD]
[TD]Percentage[/TD]
[/TR]
[TR]
[TD]Strategy A[/TD]
[TD]Strategy A invests in X Y and Z[/TD]
[TD]1.5%[/TD]
[/TR]
[TR]
[TD]Strategy B[/TD]
[TD]Strategy B shorts A B and C [/TD]
[TD]2.5[/TD]
[/TR]
[TR]
[TD]Absolute Return[/TD]
[TD][/TD]
[TD]4.0%[/TD]
[/TR]
[TR]
[TD]Strategy C[/TD]
[TD]Strategy C invests in ... [/TD]
[TD]1.2%[/TD]
[/TR]
</tbody>[/TABLE]

for the lines in bold, the strategy sub total, I'd like to add a row below that will work as the strategy title for the range below. For example, if Strategy C was Convertible arbitrage, the inserted row will say convertible abitrage. Example of final table:

[TABLE="width: 500"]
<tbody>[TR]
[TD]Absolute Return[/TD]
[TD]Description[/TD]
[TD]Percentage[/TD]
[/TR]
[TR]
[TD]Strategy A[/TD]
[TD]Strategy A invests in X Y and Z[/TD]
[TD]1.5%[/TD]
[/TR]
[TR]
[TD]Strategy B[/TD]
[TD]Strategy B shorts A B and C [/TD]
[TD]2.5[/TD]
[/TR]
[TR]
[TD]Absolute Return[/TD]
[TD][/TD]
[TD]4.0%[/TD]
[/TR]
[TR]
[TD]Convertible Arbitrage
[/TD]
[TD][/TD]
[TD]Percentage[/TD]
[/TR]
[TR]
[TD]Strategy C[/TD]
[TD]Strategy C invests in ... [/TD]
[TD]1.2%
[/TD]
[/TR]
</tbody>[/TABLE]

I'm trying to work on the condition that if a cell in the description column is blank and the cell in the 1st column is filled, insert a new row, fill in the strategy name and loop.

Thanks.
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
How would one know that Strategy C is "Convertible Arbitrage"? Is there a table somewhere?
 
Upvote 0
Yes there is a table a column over with the strategy name. It's coming from a sql query running in the workbook and would be an offset( 1,-2 ) (right?). Continuing with the example above, the row i'm trying to add is in bold

SQL Table Column
[TABLE="width: 500"]
<tbody>[TR]
[TD]Absolute value[/TD]
[TD]Blank[/TD]
[TD]Strategy B[/TD]
[TD]Strategy B...[/TD]
[TD]2.5%[/TD]
[/TR]
[TR]
[TD]Blank[/TD]
[TD]Blank[/TD]
[TD]Absolute Value[/TD]
[TD]Blank[/TD]
[TD]4.0%[/TD]
[/TR]
[TR]
[TD]Blank[/TD]
[TD]Blank[/TD]
[TD]Convertible Arb[/TD]
[TD]Blank[/TD]
[TD]Percentage[/TD]
[/TR]
[TR]
[TD]Convertible Arbitrage[/TD]
[TD]Blank[/TD]
[TD]Strategy C[/TD]
[TD]Strategy C...[/TD]
[TD]1.5%[/TD]
[/TR]
</tbody>[/TABLE]

Thanks
 
Upvote 0
Yes there is a table a column over with the strategy name. It's coming from a sql query running in the workbook and would be an offset( 1,-2 ) (right?). Continuing with the example above, the row i'm trying to add is in bold

SQL Table Column
[TABLE="width: 500"]
<tbody>[TR]
[TD]Absolute value[/TD]
[TD]Blank[/TD]
[TD]Strategy B[/TD]
[TD]Strategy B...[/TD]
[TD]2.5%[/TD]
[/TR]
[TR]
[TD]Blank[/TD]
[TD]Blank[/TD]
[TD]Absolute Value[/TD]
[TD]Blank[/TD]
[TD]4.0%[/TD]
[/TR]
[TR]
[TD]Blank[/TD]
[TD]Blank[/TD]
[TD]Convertible Arb[/TD]
[TD]Blank[/TD]
[TD]Percentage[/TD]
[/TR]
[TR]
[TD]Convertible Arbitrage[/TD]
[TD]Blank[/TD]
[TD]Strategy C[/TD]
[TD]Strategy C...[/TD]
[TD]1.5%[/TD]
[/TR]
</tbody>[/TABLE]

Thanks
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top