View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Sandy V[_6_] Sandy V[_6_] is offline
external usenet poster
 
Posts: 37
Default Set Range Var with address length over 256

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