Hi. I have this string that represents rows and row ranges separated by comma.
I want to join those rows in a single range variable (rng). I'm trying with this loop but the issue is initially rng is nothing and the "Union("nothing", Rows(s(0)))" gives error.
The complete code I have so far is:
How can be a way to do this?
Thanks for any help.
Code:
str = "1,3,6:8,11:12"
I want to join those rows in a single range variable (rng). I'm trying with this loop but the issue is initially rng is nothing and the "Union("nothing", Rows(s(0)))" gives error.
Code:
For i = LBound(s) To UBound(s)
Set rng = Union(rng, Rows(s(i)))
Next
The complete code I have so far is:
Code:
Sub JoinRanges()
Dim str As String, s, rng As Range
str = "1,3,6:8,11:12"
s = Split(str, ",")
For i = LBound(s) To UBound(s)
Set rng = Union(rng, Rows(s(i)))[COLOR=#ff0000] 'Here for first iteration I get error[/COLOR]
Next
rng.Select
End Sub
How can be a way to do this?
Thanks for any help.