私は列をループして、各行が別の列に現れる回数を数えます。これは一度動作し、正しいカウントを表示します。しかしそれ以降は、すべての行に対してゼロが表示されます。私はコードをステップし、カウンタの値は更新されません。もし誰かが見ていただければ幸いです。ネストされたForループでカウンタがインクリメントしない - Excel VBA
Sub count_tic_types()
Dim ticCountGraph As Worksheet
Dim CWData As Worksheet
'' Row count for ticCountGraph.
Dim i As Integer
'' Row count for CWData
Dim j As Integer
Dim ticCount As Integer
Dim ticAlert As Integer
Set ticCountGraph = Worksheets("ticCountGraph")
Set CWData = Worksheets("CWData")
For i = 1 To 9
'' Start the counters fresh for each new row. Ensures that
'' there's no double counting.
ticCount = 0
ticAlert = 0
'' Loop through entire target column to count the number of
'' matches there.
For j = 2 To CWData.Range("A2").End(xlDown).Row
'' Want to count values that have been Closed.
If Range("I" & j).Value = "Closed" Then
'' Increment if there are mathces.
If CWData.Range("J" & j).Value = ticCountGraph.Range("A" & i).Value Then
ticCount = ticCount + 1
'' Count blank values separately.
ElseIf IsEmpty(CWData.Range("J" & j)) Then
ticAlert = ticAlert + 1
End If
End If
Next
If ticCountGraph.Range("A" & i).Value = "Alerts" Then
ticCountGraph.Range("B" & i).Value = ticAlert
Else
ticCountGraph.Range("B" & i).Value = ticCount
End If
Next
End Sub
カラムj
意志ループを介して上記画像内の各列に一致発生 の数を数えます。
範囲( "A"&1)この1も増分またはjのようなvarにする必要がありますか? –
私はあなたのコードとデータの目標をテストするための情報をいくつか与えるべきだと思います。いくつかのブラインドショット:1)Range( "I"&j) 'にシート参照を追加する。 2) 'ticCount'カウンタは、J列の値がticCountGraph.Range(" A "&i)'に等しいときにインクリメントされますが、後者が "Alerts"の場合は 'ticCount'カウンタを書き留めません。... – user3598756