【问题标题】:Count number of cells in a column that contain data计算包含数据的列中的单元格数
【发布时间】:2014-01-17 21:32:15
【问题描述】:

我有这个代码:

Dim first As Integer
Dim Last As Integer
Dim i As Integer

For i = 1 To 17
    first = (ActiveCell.Row + 1)
    Selection.End(xlDown).Select
    Last = (ActiveCell.Row - 1)
    Range("J" & first & ":J" & Last).Select
    Selection.Value = "=J$" & (first - 1)
    Range("A" & Last + 1).Select
Next i

并且希望能够将 17 替换为变量,因为某些工作簿有一个额外的组。我不能只计算行数,因为第一个和最后一个之间有信息,但在不同的列中。

有没有办法计算在数据可能不连续的集合列中有数据的单元格的数量(然后我可以用等于变量-1的变量替换17)?

【问题讨论】:

    标签: variables excel for-loop count vba


    【解决方案1】:

    在网上找到了:谢谢。

    n = Worksheets("Sheet1").Range("A:A").Cells.SpecialCells(xlCellTypeConstants).Count
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-25
      • 1970-01-01
      • 2014-07-30
      • 1970-01-01
      • 2020-02-25
      相关资源
      最近更新 更多