Countifs

Johnson5

New Member
Joined
Sep 3, 2014
Messages
3
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.
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,214,650
Messages
6,120,734
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top