VBA Count number of times value appears in a column. With column as integer

uk747

Well-known Member
Joined
Jul 20, 2011
Messages
832
Office Version
  1. 365
Platform
  1. Windows
Wanting to count number of times a value appears in a column, however my variable is the column number not letter

So instead of counting values in range D:D it will be 4:4 although 4:4 is used for rows

I need to count if number of times ABC appears more than 3 times in column D but using the variable of 4

I used the variable as the column often changes
 

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.
Hello
There is quite a bit to unpick here.
1. What have you tried so far?
2. Must this be in VBA? Or will a formula do the job?
3. And, what happens next? Will that value be written to a sheet? Or used in another routine?
 
Upvote 0
Something like this?

VBA Code:
Sub Use_Col_number()
  Dim ColNum As Long
  
  ColNum = 4
  MsgBox WorksheetFunction.CountIf(Columns(ColNum), "ABC")
End Sub
 
Upvote 0
Solution
Something like this?

VBA Code:
Sub Use_Col_number()
  Dim ColNum As Long
 
  ColNum = 4
  MsgBox WorksheetFunction.CountIf(Columns(ColNum), "ABC")
End Sub
Yes, just needed to count the values in the column variable which I'd used VBA to get

Thanks Peter
 
Upvote 0
You're welcome. Thanks for the follow-up. :)
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,748
Members
448,989
Latest member
mariah3

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