Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Assuming you want to format cells in each row of a worksheet using a For loop, you can use the following code:

For i = 1 To numRows
    With Worksheets("Sheet1").Cells(i, 1).Resize(1, numCols)
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .Font.Bold = True
        .Interior.ColorIndex = 15
        .Borders.LineStyle = xlContinuous
        .Borders.Weight = xlThin
    End With
Next i

In this code, numRows and numCols are the number of rows and columns in your worksheet, respectively. The With statement applies the formatting to the cells in each row, starting from column 1 (Cells(i, 1)) and spanning numCols columns (Resize(1, numCols)). You can modify the formatting properties within the With statement to suit your needs.