VBA CountIf Assignment to constant

kitkatjam

New Member
Joined
Nov 30, 2018
Messages
11
I am trying to count how many times a number (Num) on one tab appears in a specified column of another tab. The Num is a variable, it is part of a do while loop where the cell itself changes and the value in the cell changes based on user input. Therefore, I have no way of knowing what the CountIf is actually searching for and need it to search for a variable.

I tried setting Num as Range and Double for the below:

WorksheetFunction.CountIf(Range("C:C"), Num) = b

But I keep getting "Assignment to constant not permitted". Everything I've searched for on CountIf has a specific word in the search part, is it even possible to use a variable? I'm not sure what part I'm screwing up, any help would be greatly appreciated!

Thank you!
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Welcome to the forum. :)

Assuming b is a variable, you simply have the assignment backwards:

Code:
b = WorksheetFunction.CountIf(Range("C:C"), Num)
 
Upvote 0

Forum statistics

Threads
1,215,050
Messages
6,122,868
Members
449,097
Latest member
dbomb1414

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