How to Variable Reference Row Ranges?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm trying to use variables to reference row ranges but don't know the syntax
or correct command. Instead of using a command like:

Range("5:9")

I'm trying to reference a number of row groups i.e. 5:9, 10:14, 15:19 and
would like to be able to use a command like:

Range("var1,var2") but this doesn't seem to work.

Any ideas....
 
One way:

one way:

Dim var1 As String
Dim var2 As String
var1 = "5:9"
var2 = "10:14"
Debug.Print Union(Range(var1), Range(var2)).Address

another:

Debug.Print Range(var1 & "," & var2).Address
 
Tom...

Thx for your comment. Actually not trying to reference the rows at the same
time but conditional on other factors i.e.

If EventA then
Var1 = 10
var 2 = 14
else
Var 1 = 20
var 2 = 24
End if
Range("var1, var2")

Any thoughts?
 
One way:

Range(var1 & ":" & var2)


VicWestVan said:
Tom...

Thx for your comment. Actually not trying to reference the rows at the same
time but conditional on other factors i.e.

If EventA then
Var1 = 10
var 2 = 14
else
Var 1 = 20
var 2 = 24
End if
Range("var1, var2")

Any thoughts?
 

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

Back
Top