ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Use "For... Each" to Iterate Through a Cells Collection? (https://www.excelbanter.com/excel-programming/356415-use-each-iterate-through-cells-collection.html)

BobbyMurcerFan

Use "For... Each" to Iterate Through a Cells Collection?
 

In Excel 2000 VBA, Is it possible to use "For... Each" to iterat
through a Cells collection?

Something along the lines of:

Code
-------------------

' ILLUSTRATIVE PSUEDO CODE THAT DOESN'T WORK

Dim celX as Cell ' I realze that Excel's VBA doesn't actually have a Cell object


' Iterate Through rngMyRange's Cells Collection
For Each celX in rngMyRange.Cells

MsgBox(celX.Value)

Next cel
-------------------

While I realize the above code won't actually work, IS there a way t
use For Each with the Cells collection?

Presently, I'm using the Count property to get the number of cells an
using that value in a For Loop iteration test.

Here's and example:

Code
-------------------
' WON'T WORK FOR CELL OBJECT
Sub ForLoopCell()

Dim iCntr As Integer, rngTest As Range

Set rngTest = ActiveSheet.Range("B1:B10")


' Iterate Through Cells Collection By Using A Counter
For iCntr = 1 To rngTest.Cells.Count

MsgBox (rngTest.Cells(iCntr).Value)

Next iCntr

End Su
-------------------


Using a For... Each would be easier, but is there a way to do it?

THANKS VERY MUCH!! :

--
BobbyMurcerFa
-----------------------------------------------------------------------
BobbyMurcerFan's Profile: http://www.excelforum.com/member.php...fo&userid=1110
View this thread: http://www.excelforum.com/showthread.php?threadid=52394


Chip Pearson

Use "For... Each" to Iterate Through a Cells Collection?
 
Try

Dim Rng As Range
For Each Rng In rngMyRange.Cells
Debug.Print Rng.Text
Next Rng


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"BobbyMurcerFan"
<BobbyMurcerFan.24vqrb_1142709601.6373@excelforu m-nospam.com
wrote in message
news:BobbyMurcerFan.24vqrb_1142709601.6373@excelfo rum-nospam.com...

In Excel 2000 VBA, Is it possible to use "For... Each" to
iterate
through a Cells collection?

Something along the lines of:

Code:
--------------------

' ILLUSTRATIVE PSUEDO CODE THAT DOESN'T WORK

Dim celX as Cell ' I realze that Excel's VBA doesn't
actually have a Cell object


' Iterate Through rngMyRange's Cells Collection
For Each celX in rngMyRange.Cells

MsgBox(celX.Value)

Next celX
--------------------

While I realize the above code won't actually work, IS there a
way to
use For Each with the Cells collection?

Presently, I'm using the Count property to get the number of
cells and
using that value in a For Loop iteration test.

Here's and example:

Code:
--------------------
' WON'T WORK FOR CELL OBJECT
Sub ForLoopCell()

Dim iCntr As Integer, rngTest As Range

Set rngTest = ActiveSheet.Range("B1:B10")


' Iterate Through Cells Collection By Using A Counter
For iCntr = 1 To rngTest.Cells.Count

MsgBox (rngTest.Cells(iCntr).Value)

Next iCntr

End Sub
--------------------


Using a For... Each would be easier, but is there a way to do
it?

THANKS VERY MUCH!! :)


--
BobbyMurcerFan
------------------------------------------------------------------------
BobbyMurcerFan's Profile:
http://www.excelforum.com/member.php...o&userid=11107
View this thread:
http://www.excelforum.com/showthread...hreadid=523941





All times are GMT +1. The time now is 09:21 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com