Macro to count rows and repeat formula across

somesoldiers

Board Regular
Joined
Feb 23, 2008
Messages
199
Hi Guys</SPAN>

How to I change the below so that the formula will be repeated row count times across rather than down?</SPAN>
So my row count is 19, I want to copy the formula from H4 to AA4 rather than from H4 down to H23</SPAN>

Thanks</SPAN>

Noel</SPAN>
LR = Sheets("Balance Sheet - AM").Cells(Rows.Count, "A").End(xlUp).Row</SPAN>

Range("H4:H" & LR).FormulaR1C1 = _</SPAN>
"=IF(ISERROR(VLOOKUP(C[-7],MAP!C[-4]:C[-3],2,0)),""N"",(VLOOKUP(C[-7],MAP!C[-4]:C[-3],2,0)))"</SPAN>
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Give this a try...

Code:
LR = Sheets("Balance Sheet - AM").Cells(4, Columns.Count).End(xlToLeft).Column
 

Range("H4").Resize(, LR - 7).FormulaR1C1 = _
 "=IF(ISERROR(VLOOKUP(C[-7],MAP!C[-4]:C[-3],2,0)),""N"",(VLOOKUP(C[-7],MAP!C[-4]:C[-3],2,0)))"
 
Upvote 0
Give this a try...

Code:
LR = Sheets("Balance Sheet - AM").Cells(4, Columns.Count).End(xlToLeft).Column
 

Range("H4").Resize(, LR - 7).FormulaR1C1 = _
 "=IF(ISERROR(VLOOKUP(C[-7],MAP!C[-4]:C[-3],2,0)),""N"",(VLOOKUP(C[-7],MAP!C[-4]:C[-3],2,0)))"

Thanks Rick- I want to count the number of Rows on the Balance Sheet tab in column D. I think your formula is changing this to count the columns?
 
Upvote 0
Range("H4").Resize(, LR - 1).FormulaR1C1 = _
"=IF(ISERROR(VLOOKUP(C[-7],MAP!C[-4]:C[-3],2,0)),""N"",(VLOOKUP(C[-7],MAP!C[-4]:C[-3],2,0)))"

Think I'm there, kept my first line and changed your second to LR - 1- seems to have worked, will check back if I have any more problems- thanks guys
 
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,597
Members
449,038
Latest member
Arbind kumar

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