The following example fills the first 20 cells in the third column with values between 5 and 100, incremented by 5. To loop through a range of cells, use a variable with the Cells property in a loop. To do that, on the Developer tab, click Use Relative References, and then click Record Macro.
Note You can record macros that use the Offset property to specify relative references instead of absolute references. Sub Underline()ĪctiveCell.Offset(1, 3).Font.Underline = xlDouble In the following example, the contents of the cell that is one row down and three columns over from the active cell on the active worksheet are formatted as double-underlined.
A common way to work with a cell relative to another cell is to use the Offset property.