VBA - 计算一行中填充单元格的数量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17708220/
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
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 16:11:08 来源:igfitidea点击:
VBA - Counting the number of filled cells in a row
提问by user2578013
The following is my code so far. Any tips?
以下是我到目前为止的代码。有小费吗?
With wSheet
colCount = .Range(1 & .Columns.Count).End(xlToRight).Column
End With
What am i doing wrong?
我究竟做错了什么?
回答by David Zemens
Try:
尝试:
colCount = wSheet.UsedRange.Rows(1).Columns.Count
(revised)
(修改)
回答by Doug Glancy
To get the number of the rightmost filled column:
要获取最右边的填充列的编号:
colCount = .Cells(1, .Columns.Count).End(xlToLeft).Column
To get the count of non-blank cells, as your title says:
要获取非空白单元格的数量,正如您的标题所说:
Application.WorksheetFunction.CountA(.Rows(1).EntireRow.Cells)