Correct Syntax for dynamic row

kjohn25744

New Member
Joined
Oct 11, 2021
Messages
4
Office Version
  1. 365
Platform
  1. Windows
I need to replace the row number in a range with a variable and can't seem to get the correct syntax. I have the code written to get the last row in a column and want to use that variable I named lRow. Here is the line in the code from a Marco I recorded that needs to be replaced.

Range ("D24").Select

My variable for the last row is called lRow. I am trying to replace the "24" in the above select with the following but I can't seem to find the correct syntax. Here is what I have tried.

Range("D & lRow").Select
Range(D" & lRow").Select
 

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.
You can use either:

Code:
Range("D" & lRow).Select

or:

Code:
Cells(lRow, "D").select

though you rarely need to actually select a cell in code.
 
Upvote 0
Solution
Hi & welcome to MrExcel.
Try
VBA Code:
Range("D" & lRow).Select
 
Upvote 0
Thanks Guys, I knew it was simple but couldn't see it. Worked just like I needed it to work.
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,877
Messages
6,122,051
Members
449,064
Latest member
scottdog129

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