Count If Macro

ajamesf89

New Member
Joined
Oct 15, 2014
Messages
8
I can not figure out a multiple count if macro. Basically i want it to search a column (read d2:d3000) and find a set of letters such as "CB", "KP2" and throw out all the counts. I tried to record the macro then put multiple lines in but this did not work. can someone assist?

below is my example
Sub WeeklyCountIfs()
'
' WeeklyCountIfs Macro
'

'
ActiveCell.FormulaR1C1 = "=COUNTIF(R[-2009]C4:R[989]C4,""CB"")"
ActiveCell.FormulaR1C1 = "=COUNTIF(R[-2009]C4:R[989]C4,""PRT"")"
ActiveCell.FormulaR1C1 = "=COUNTIF(R[-2009]C4:R[989]C4,""CCC"")"
ActiveCell.FormulaR1C1 = "=COUNTIF(R[-2009]C4:R[989]C4,""DEM"")"
ActiveCell.FormulaR1C1 = "=COUNTIF(R[-2009]C4:R[989]C4,""DEL"")"
ActiveCell.FormulaR1C1 = "=COUNTIF(R[-2009]C4:R[989]C4,""KGD"")"
ActiveCell.FormulaR1C1 = "=COUNTIF(R[-2009]C4:R[989]C4,""RC"")"
ActiveCell.FormulaR1C1 = "=COUNTIF(R[-2009]C4:R[989]C4,""RW"")"
ActiveCell.FormulaR1C1 = "=COUNTIF(R[-2009]C4:R[989]C4,""PH"")"
ActiveCell.FormulaR1C1 = "=COUNTIF(R[-2009]C4:R[989]C4,""KPH"")"
ActiveCell.FormulaR1C1 = "=COUNTIF(R[-2009]C4:R[989]C4,""KCC"")"
ActiveCell.FormulaR1C1 = "=COUNTIF(R[-2009]C4:R[989]C4,""KDM"")"
ActiveCell.FormulaR1C1 = "=COUNTIF(R[-2009]C4:R[989]C4,""KDL"")"
ActiveCell.FormulaR1C1 = "=COUNTIF(R[-2009]C4:R[989]C4,""UGD"")"
ActiveCell.FormulaR1C1 = "=COUNTIF(R[-2009]C4:R[989]C4,""KRC"")"
ActiveCell.FormulaR1C1 = "=COUNTIF(R[-2009]C4:R[989]C4,""PM"")"
ActiveCell.FormulaR1C1 = "=COUNTIF(R[-2009]C4:R[989]C4,""PM1"")"
ActiveCell.FormulaR1C1 = "=COUNTIF(R[-2009]C4:R[989]C4,""PM2"")"
ActiveCell.FormulaR1C1 = "=COUNTIF(R[-2009]C4:R[989]C4,""KPM"")"
ActiveCell.FormulaR1C1 = "=COUNTIF(R[-2009]C4:R[989]C4,""KP2"")"
ActiveCell.FormulaR1C1 = "=COUNTIF(R[-2009]C4:R[989]C4,""KP1"")"

End Sub
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Try
Code:
ActiveCell.FormulaR1C1 = "=COUNTIF(R2C4:R[-1]C4,""CB"")"
 
Upvote 0
this did work thank you! anyway to make it so it counts all of my lines and just spaces them out by a comma or labels them for me? I dont want it to count based off two criteria, such as count if it meets this but it also has to meet this as well to count as 1. I just want counts for all those singly because i am looking through 2500 plus lines at a time.
 
Upvote 0
How about
Code:
Sub MyCountif()
   Dim Ary As Variant
   Dim Msg As String
   Dim i As Long
   
   Ary = Array("CB", "PRT", "CCC")
   For i = 0 To UBound(Ary)
      Msg = Msg & Application.CountIf(Range("D:D"), Ary(i)) & " " & Ary(i) & vbLf
   Next i
   MsgBox Msg
End Sub
Just add the rest of your values to the array
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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