Macro to count rows and repeat formula across

somesoldiers

Board Regular
Joined
Feb 23, 2008
Messages
190
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>
 

Some videos you may like

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
36,675
Office Version
  1. 2010
Platform
  1. Windows
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)))"
 

somesoldiers

Board Regular
Joined
Feb 23, 2008
Messages
190
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?
 

somesoldiers

Board Regular
Joined
Feb 23, 2008
Messages
190
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
 

Watch MrExcel Video

Forum statistics

Threads
1,122,224
Messages
5,594,914
Members
413,952
Latest member
JGer

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
Top