Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Reference range row and column in VBA

  Asked By: Archie    Date: Dec 22    Category: MS Office    Views: 1250
  

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?

Share: 

 

3 Answers Found

 
Answer #1    Answered By: Beaudi Smith     Answered On: Dec 22

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: Sophia Campbell     Answered On: Dec 22

Thanks a lot. It works.................

 
Answer #3    Answered By: Andrew Brown     Answered On: Dec 22

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.




Tagged: