Find color and value in column to count with vba I need help to resolve an error
ID: 637978 • Letter: F
Question
Find color and value in column to count with vba
I need help to resolve an error with this code. When I run this macro the count for all conditions that not correct.
In the first condition the correct value is 1 and the macro send 7
In second condition the correct value is 6 and the macro send 15
In third condition the correct value is 10 and the macro send 17
Sub Count_Yellow2()
rng_RngColA = Range("B1:B1000").Count
rng_RngColA = Range("E1:E1000").Count
For i = 1 To rng_RngColA
'Yellow in column E and Value GT1,GT2,GT3 with Pink in column B
If Cells(i, 5).Interior.Color = RGB(255, 255, 0) And Cells(i, 5).Value Like "*GT1*" _
And Cells(i, 2).Interior.Color = RGB(255, 181, 197) Then
v_CountYellow = v_CountYellow + 1
Range("D1").Value = v_CountYellow
End If
If Cells(i, 5).Interior.Color = RGB(255, 255, 0) And Cells(i, 5).Value Like "*GT2*" _
And Cells(i, 2).Interior.Color = RGB(255, 181, 197) Then
v_CountYellow = v_CountYellow + 1
Range("D2").Value = v_CountYellow
End If
If Cells(i, 5).Interior.Color = RGB(255, 255, 0) And Cells(i, 5).Value Like "*GT3*" _
And Cells(i, 2).Interior.Color = RGB(255, 181, 197) Then
v_CountYellow = v_CountYellow + 1
Range("D3").Value = v_CountYellow
End If
Next i
End Sub
Thanks for help !!
Explanation / Answer
Hi..
Do not use the same variable name v_CountYellow in each If case, because the count value is not erased when each if case is ended, instead the count is accumulative....
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.