View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Ed Ferrero[_5_] Ed Ferrero[_5_] is offline
external usenet poster
 
Posts: 20
Default Can I use array to simplify this code.

Hi broogle,

Try something like...

Sub test()

Dim rngArr(3) As Variant
Dim rng As Variant

' populate the array
Set rngArr(1) = Worksheets(1).Range("A1:A5")
Set rngArr(3) = Worksheets(1).Range("C1:C5")

For Each rng In rngArr
' because we have declared a variant array, we can test for empty members
If Not IsEmpty(rng) Then
' do something... (place your own codew here)
MsgBox rng.Address
End If
Next

End Sub

Ed Ferrero

Can I use array to simplify this code.
Appreciate your help. Thanks

sub test()
Dim rngJ As Range
Dim rngK As Range
Dim rngL As Range
.
.
.
For Each Cell In rngK
---code---
next

For Each Cell In rngL
---code--- (same as above)
next

For Each Cell In rngM
---code--- (same as above)
next
.
.
.
end sub

------------------------

Notes: rngK, rngL and rngM located in different sheets.