Excel VBA - 格式化整列,不包括标题行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9730842/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Excel VBA - format a whole column excluding the heading line
提问by HL8
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.
谢谢你。
回答by Doug Glancy
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
回答by mattboy
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.
这将不会选择整列,而是选择从第一行到最后一行的非空白行的范围。但是,如果第一行和最后一行之间有空单元格,这不是合适的解决方案。