簡體   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