1. Step 1 declares two Range object variables, one called MyRange to hold the entire target range, and the other called MyCell to hold each cell in the range as the macro enumerates through them one by one.
2. Step 2 fills the MyRange variable with the target range. In this example, we are using the selected range — the range that was selected on the spreadsheet. You can easily set the MyRange variable to a specific range such as Range(“A1:Z100”). Also, if your target range is a named range, you can simply enter its name: Range(“MyNamedRange”).
3. Step 3 starts looping through each cell in the target range, activating each cell.
4. The WorksheetFunction object provides a way for us to be able to run many of Excel's spreadsheet functions in VBA. Step 4 uses the WorksheetFunction object to run a CountIf function in VBA.
In this case, we are counting the number of times the active cell value (MyCell.Value) is found in the given range (MyRange). If the CountIf expression evaluates to greater than 1, the macro changes the interior color of the cell.
5. Step 5 loops back to get the