Including a Variable in A Range Statement

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
How do I incorporate a variable into a range statement?

In the code below, I want to define a range between A1 and J{whatever the last row is}

Rich (BB code):
llastrow = Range("A65536").End(xlUp).Row
         MsgBox ("The Last Row Is: ") & llastrow
         With .Range("A1:J??????")
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Code:
llastrow = Range("A65536").End(xlUp).Row
         MsgBox ("The Last Row Is: ") & llastrow
         With .Range("A1"),Resize(llastrow)
 
Upvote 0
Either

Code:
llastrow = Range("A65536").End(xlUp).Row
MsgBox ("The Last Row Is: ") & llastrow
With .Range("A1:J" & llastrow)
...
End With

or

Code:
llastrow = Range("A65536").End(xlUp).Row
MsgBox ("The Last Row Is: ") & llastrow
With .Range(Cells(1,"A"),Cells(llastrow,"J"))
...
End With

or without using variable

Code:
With .Range(Cells(1,"A"),Cells(Rows.Count,"A").End(xlup).Offset(,9))

End With
 
Upvote 0
LOL ... thanks Vog. I tried every combination of similar but that one.
I think I get thrown off with the quotation marks.

Jenn
 
Upvote 0
Thanks Donkey for your reply also.
I like your picture :)
 
Upvote 0

Forum statistics

Threads
1,214,611
Messages
6,120,513
Members
448,967
Latest member
screechyboy79

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