Using Address in Range Definition??

G

Guest

Hi Folks,

Need some more help here.....Below is macro used to find the address of the
last cell in the last column used and store that address in variable "R"...

Sub lastcell()

Dim R As String

Cells(Rows.Count, "B").End(xlUp).Select
Selection.End(xlToRight).Select
R = Selection.Address
MsgBox (R)

End Sub

MsgBox will show the Address of the last cell. Assume last cell is H8,
Msgbox will display "$H$8".....This address is also stored in "R".

My question is how do I use the data stored in "R" in a Range
call....similar to the following...

Range("B4:R").Select

Thanks in advance,

Don
 
G

Guest

Concatenate like you would any other string
Range("B4:"&R).Select

Also - just as a pointer, it is not usually necessary to select cells/ranges
in order to work with them. With larger macros, it can make a difference in
amount of time it takes to process.

Sub lastcell()
Dim R As String

R = Cells(Rows.Count, "B").End(xlUp).End(xlToRight).Address
MsgBox (R)

End Sub
 
G

Guest

Hi renegan,

Thank you very much for the quick reply....works like a charm.....:)

Don
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top