Writing range variable in VBA

millhouse123

Active Member
Joined
Aug 22, 2006
Messages
334
Below is a small section of code I have been working on.
In Its current state it works fine however I need to make the Column references dynamic. So in this case I need to assign "Q" to a variable.
Q currently Represents the last column in my spreadsheet. I assign it to a variable FinalColumn2 --- FinalColumn2 = WS2.Cells(3, 230).End(xlToLeft).Column --- Which works great. I just can't figure out how to us the FinalColumn2 variable instead of the Q.

Any help would be great.


Range("Q4:Q" & FinalRow2).Formula = "=VLOOKUP(A4," & WS1.Name & "!" & PRange1.Address & ",3,)"
[/code]
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
Hi,

try this
Code:
FinalColumn2 = WS2.Cells(3, 230).End(xlToLeft).Column
Range(Cells(4, FinalColumn2), Cells(FinalRow2, FinalColumn2)).Formula = "=VLOOKUP(A4," & WS1.Name & "!" & PRange1.Address & ",3,)"
kind regards,
Erik
 

Forum statistics

Threads
1,171,719
Messages
5,877,120
Members
433,233
Latest member
Haripriya

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