Writing range variable in VBA

millhouse123

Active Member
Joined
Aug 22, 2006
Messages
335
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

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
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
 
Upvote 0

Forum statistics

Threads
1,215,425
Messages
6,124,827
Members
449,190
Latest member
rscraig11

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