繁体   English   中英

Excel(需要VBA吗?)选择一行中具有特定格式并已填充的所有单元格,然后对它们进行计数。 在公式中使用该计数

[英]Excel (VBA needed?) Select all Cells in a row that have a certain format and are filled, then count them. Use that count in a formula

分析我为公司获得的一些数据,我需要对单元进行计数,因此我可以使用该计数来计算公式。
CurrentRegion不起作用。 这是需要满足的条件。

计数的单元格必须是:

  • 某一行(附近还有其他填充的单元格,这就是CurrentRegion不起作用的原因)。
  • 特定格式(mm:ss)
  • 2个单元之间充满字符串。

该数据是自动收集的,因此不会设置用字符串填充的字段的坐标。

(设置)行如下所示:

Description  
Description  
...  
Time  
Time  
Time            <- This is the data that I want to count.  
Time  
Time  
...  
Description  
Time  
Time  
...  

如果只是其中之一,我可能会明白,但是对我来说,对于VBA来说还比较陌生,这很难。
我感谢所有提示。 我不希望有人为我编写代码

才开始...:

Dim e As Integer

e = 0
For i = 1 To 9999
    If Cells(i, 1).Value = "" Then Exit For
    If IsNumeric(Cells(i, 1).Value) Then
        e = e + 1
        ' Debug.Print Format(Cells(i, 1).Value, "h:m:s")
    Else
        If e <> 0 Then Debug.Print "Count = " & e
        e = 0
    End If
Next

宏为每个部分打印连续时间值的数量。
带注释的打印显示了格式化的时间。
您需要添加代码才能继续...
如果还需要行范围,请修改一些代码:

Dim e, i, Addr1 As Integer

e = 0
For i = 1 To 9999
    If Cells(i, 1).Value = "" Then Exit For
    If IsNumeric(Cells(i, 1).Value) Then
        If e = 0 Then Addr1 = i
        e = e + 1
        ' Debug.Print Format(Cells(i, 1).Value, "h:m:s")
    Else
        If e <> 0 Then Debug.Print "Count = " & e & " - Range of Rows: " & Addr1 & " -> " & i - 1
        e = 0
    End If
Next

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM