Excel VBA - format a whole column excluding the heading line

与世无争的帅哥 提交于 2020-01-01 09:40:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!