VBA example - Excel 2007: loop to fill color last row
VBA code to fill color last row Suppose that your Excel sheet contains the information as shown below. If you want to locate and fill color the last row that contains data, How can you do? You can do it simply by using VBA loop to find that row.
| VBA for Excel |
| Excel 2007 |
| VBA loop |
| VBA array |
To run this example VBA code, you will need a Form, and a CommandButton. You may type the sample text above in to your current worksheet.
VBA code for this example:
Option Explicit Private Sub CommandButton1_Click() Dim row As Integer row = 1 While Trim(Cells(row, 1)) <> "" 'find the last row row = row + 1 Wend Range("A" & row - 1).Select 'select the last row and fill color With Selection.Interior .Color = RGB(20, 100, 10) End With