Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
how can I disable "cutting cells" and "drag and drop "in excel ? | Excel Worksheet Functions | |||
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell | Excel Discussion (Misc queries) | |||
Check if cells contain the word "Thailand", return "TRUE" | Excel Worksheet Functions | |||
Can you "duplicate" "copy" listboxes and code to multiple cells? | Excel Programming | |||
Using "Cells" to write "Range("A:A,H:H").Select" | Excel Programming |