View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
Wei-Dong Xu [MSFT] Wei-Dong Xu [MSFT] is offline
external usenet poster
 
Posts: 120
Default Non-Contiguos Range Iteration

Hi Matthew,

Thanks for participating the community!

From my understanding to this issue, you ar going to perform some calculations on two non-contiguous ranges.

I'd suggest you can use one Range array to store each range. Then with the help of one loop, it will be easily for you to iterate the value in the
two ranges. I create one sample for you.
'Code begin ----------------------------------------------------
Sub NoncontiguousRange()

Dim objSht As Worksheet
Dim oRng As Range
Dim oRng2nd As Range
Dim oRngRlt As Range
Dim oCell As Range

Set objSht = Application.ActiveSheet
Set oRng = objSht.Range("D5:F7")
Set oRng2nd = objSht.Range("I5:J7")
Dim oRngArr(2) As Range
Set oRngArr(1) = oRng
Set oRngArr(2) = oRng2nd

Dim oRngTmp As Range
For i = 1 To UBound(oRngArr)
For Each oCell In oRngArr(i).Rows(1).Cells
Debug.Print oCell.Value
Next
Next

End Sub
'Code end ------------------------------------------------------

Please feel free to let me know if you have any questions.

Have a nice day!

Wei-Dong Xu
Microsoft Product Support Services
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.