问题
I want to format a column but to exclude the first row as this is the header:
My current Code is:
Sheets("Sheet1").Columns(3).NumberFormat = "#,##0"
Thank you.
回答1:
Unless the header is a number you shouldn't need to do this, I don't think. The number format won't affect text (at least not much). But here's a way:
With ThisWorkbook.Sheets("Sheet1")
.Columns(3).Resize(.Rows.Count - 1, 1).Offset(1, 0).NumberFormat = "#,##0"
End With
回答2:
Alternatively
Sheets("Sheet1").Range(cells(2,3), cells(2,3).end(xldown)).NumberFormat = "#,##0"
This would select not the entire column, but the range from your first to last non-blank row. If you have empty cells in between your first and last row, this is not an appropriate solution, however.
来源:https://stackoverflow.com/questions/9730842/excel-vba-format-a-whole-column-excluding-the-heading-line