Iterate through non contiguous range of cells

Trebormac

New Member
Joined
Sep 10, 2009
Messages
32
Hi All,

I need to iterate through a bunch of cells that are contiguous, e.g., A1077, A1076, B1086, B1087, A1095 etc and take some action based on the cell vaalue. There are about a hundred or so cells that I need to examine.

What is the best way to handle this...should I put the cell addresses in an array?

Thanks for any suggestions!

Trebormac
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
If you are only ever using the same set of cells, you can create a named range that includes all of them. Select them all, and assign a name to the group, then use the defined name in your code

Alternatively, you can use UNION (range 1, range 2... range z) to link them into a single range programatically
 
Upvote 0
You could use a range variable to loop through the range
Code:
Dim oneCell As Range

For Each oneCell In ThisWorkbook.Sheets("Sheet1").Range("A1077, A1076, B1086, B1087, A1095")
    MsgBox oneCell.Address
Next oneCell
 
Upvote 0

Forum statistics

Threads
1,224,517
Messages
6,179,233
Members
452,898
Latest member
Capolavoro009

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top