I want to create a range expression to use within Union()
method.
I have this code so far:
Sub RangeExpresion()
Dim str As String, s
str = "2,10"
s = Split(str, ",")
' (1) If I do this it works. It selects rows 2 and 10
Union(Rows("" & s(0) & ""), Rows("" & s(1) & "")).Select
' (2) If I do this doesn't work. The expression is not correct. I get error
h = "Rows("" & s(0) & ""), Rows("" & s(1) & "")"
Union(h).Select
End Sub
As you can see, in first Union()
command I use inside the expression Rows("" & s(0) & ""), Rows("" & s(1) & "")
and is accepted and rows 2 and 10 are selected.
In second Union()
I first try to store in a variable the same expression that works above, but this time I get error
argument not optional
How would be the way to do this? Thanks in advance.