Page 12 of 24PREVNEXT

Get in the loop with Excel macros

A For Each...Next loop

A For Each…Next Loop makes the word "OK" darker than other text, everywhere in a selection.

You would use the For Each…Next loop to perform an action on every cell in a range of data. Suppose, for example, that you wanted to make the word "OK" darker than other text everywhere in a selected range. Your code would look like this:

For Each MyCell In Selection

"MyCell" means whatever cell the loop is working on, and "For Each" means that the loop will work on all cells in the selection. If the loop finds a cell containing only the word "OK", then it makes that word darker. (The appearance of text is controlled by the Font property, and the Bold property means darker text.)

Page 12 of 24PREVNEXT