Hi forum crew,
I'm trying to do a countif function with visual basic. I have two columns of data similar to below but much longer:
1 1
1 2
1 3
2
1
2
2
2
2
2
I am trying to have the third column show a count of how many of the second column numbers there are in the first column ie.:
4
6
0
Direct entry into excel is working well with =COUNTIF(A1:A10,"="& B1)
In Visual Basic I have tried:
Sub countif()
Dim z As Integer
z = 0
While (z < 3)
z = z + 1
Range("C" & z).Select
ActiveCell.Formula = "=COUNTIF(A1:A10,"=" & B" & z & ")"
Wend
End Sub
I think it is a problem with my "" and have tried a few alterations. Any help is appreciated.
I'm trying to do a countif function with visual basic. I have two columns of data similar to below but much longer:
1 1
1 2
1 3
2
1
2
2
2
2
2
I am trying to have the third column show a count of how many of the second column numbers there are in the first column ie.:
4
6
0
Direct entry into excel is working well with =COUNTIF(A1:A10,"="& B1)
In Visual Basic I have tried:
Sub countif()
Dim z As Integer
z = 0
While (z < 3)
z = z + 1
Range("C" & z).Select
ActiveCell.Formula = "=COUNTIF(A1:A10,"=" & B" & z & ")"
Wend
End Sub
I think it is a problem with my "" and have tried a few alterations. Any help is appreciated.