MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Loop through range of cells


Posted by CPE on February 01, 2002 7:07 AM

If i select a range of cells, how can I use a for each loop to loop through each cell in the selection in turn?

Chris


Posted by Benny on February 01, 2002 7:08 AM

Try this VB code:

For Each X In Selection
MsgBox X
Next X

Posted by G.K. on February 04, 2002 6:02 PM

Try using Autofilter in Excel. Click somewhere in your data (assuming you have labeled each range above your data). Turn on autofilter, and list boxes with down arrow will show at top of each column. You can specify a custom selection, or use form and set criteria, bringing up your row of data in a form mode for looking at. I use the autofilter a lot. You can turn it off. The data when it filters it, doesn't move the data, since the rows still stay the same that the data is on.