Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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



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
how can I disable "cutting cells" and "drag and drop "in excel ? mwoody Excel Worksheet Functions 4 August 25th 08 03:53 PM
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
Check if cells contain the word "Thailand", return "TRUE" ali Excel Worksheet Functions 7 September 14th 07 09:53 AM
Can you "duplicate" "copy" listboxes and code to multiple cells? HotRod Excel Programming 1 September 1st 04 05:03 PM
Using "Cells" to write "Range("A:A,H:H").Select" Trip Ives[_2_] Excel Programming 3 June 5th 04 03:13 PM


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

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"