View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Robin Hammond[_2_] Robin Hammond[_2_] is offline
external usenet poster
 
Posts: 575
Default Looping through range newbie question

Frank,

Try something like this

Sub PrintRangeValues(rngOutput As Range)
Dim lRow As Long
Dim nCol As Integer
With rngOutput
For lRow = 1 To .Rows.Count
For nCol = 1 To .Columns.Count
Debug.Print .Cells(lRow, nCol).Value
Next nCol
Next lRow
End With
End Sub

Robin Hammond
www.enhanceddatasystems.com

"Frank Rizzo" wrote in message
...
Sorry, for what maybe a really simple question - i am a newbie.

I've found that I can loop through a range via the following statement:

For Each c In MyRange.Cells
Debug.Print c.Value
Next

However, I need to know when the next row starts, so I am looking to loop
using the following construct:

For Each oRow In MyRange.Rows
For Each oCol In MyRange.Columns(oRow.index)
Debug.Print oCol.Cell.Value
Next
Next

But I can't figure out how to make it work. Is this possible? Or maybe I
am taking the wrong approach?

Thanks