S
Sandy V
I want to set a range variable with the address of
variable already set in another workbook. The problem is
if the address length is more than 256 (approx 17 to 25
areas).
The following seems to work, but the Loop & Union method
is slow with a very large number of areas.
Sub CopyRngVar()
Dim Rng1 As Range 'in active WB
Dim Rng2 As Range 'destined another WB
Dim a As Range
Set Rng1 = Range("A1:B3,A5:B6")
With Workbooks("Book2").Worksheets("Sheet1")
'this works if address length < 256
'Set Rng2 = .Range(Rng1.Address)
For Each a In Rng1.Areas
If Rng2 Is Nothing Then
Set Rng2 = .Range(a.Address)
Else
Set Rng2 = Union(Rng2, .Range(a.Address))
End If
Next
End With
Rng2.Interior.ColorIndex = 5
End Sub
Any ideas for a something more efficient much appreciated,
TIA,
Sandy
Savituk yahoo co uk
variable already set in another workbook. The problem is
if the address length is more than 256 (approx 17 to 25
areas).
The following seems to work, but the Loop & Union method
is slow with a very large number of areas.
Sub CopyRngVar()
Dim Rng1 As Range 'in active WB
Dim Rng2 As Range 'destined another WB
Dim a As Range
Set Rng1 = Range("A1:B3,A5:B6")
With Workbooks("Book2").Worksheets("Sheet1")
'this works if address length < 256
'Set Rng2 = .Range(Rng1.Address)
For Each a In Rng1.Areas
If Rng2 Is Nothing Then
Set Rng2 = .Range(a.Address)
Else
Set Rng2 = Union(Rng2, .Range(a.Address))
End If
Next
End With
Rng2.Interior.ColorIndex = 5
End Sub
Any ideas for a something more efficient much appreciated,
TIA,
Sandy
Savituk yahoo co uk