MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Reference range row and column in VBA

  Asked By: Carlton    Date: Feb 26    Category: MS Office    Views: 7879

I am a VBA beginner and I am not sure if this is a stupid question.

I have range1=range("A1:F500") and I want to put "F" and "500" as macro
variables, for instance

sub aaa(Dim lastcolumn as long, Dim lastrow as long)
range1=range("A1:lastcolumn lastrow")
end sub

Is there anyway to do that?



2 Answers Found

Answer #1    Answered By: Dylan Evans     Answered On: Feb 26

Yes. Inside your range  call you are providing the range as a string. You
just need to use the appropriate string concatenation sequence to get the
range string you want. & (ampersand) is the string concatenation operator
in VBA.

range("A1:" & lastcolumn & lastrow)

Answer #2    Answered By: Kerry Wright     Answered On: Feb 26

Yes you can do this.
Get value of lastcolumn & lastrow in to any variable eg. "f"
& use it inside the range  input as range1 = range("A1:A"&f)

Didn't find what you were looking for? Find more on Reference range row and column in VBA Or get search suggestion and latest updates.