Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Looping through range newbie question

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Real Newbie newbie question Dave New Users to Excel 0 January 10th 07 07:55 PM
Newbie Question - Subtraction Formula Question [email protected] Excel Discussion (Misc queries) 3 May 5th 06 05:50 PM
looping question luke New Users to Excel 4 June 3rd 05 01:19 PM
Looping Question MWS Excel Programming 0 October 27th 04 01:49 PM
Looping question Rune_Daub[_8_] Excel Programming 1 November 8th 03 04:06 PM


All times are GMT +1. The time now is 02:08 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"