Range Issue

pratiksuhasaria

New Member
Joined
Mar 26, 2019
Messages
24
this is the excel forumla which i used to calculate count of values which are less than and equal to E2
=COUNTIF(Sheet1!D2:D13,"<="&E2)

but i want this same thing to be used in vba so i used this function
Application.WorksheetFunction.CountIf(rng, Range("<=" & "E2"))

but it showing error of type mismatch

help me out with this
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
this is the excel forumla which i used to calculate count of values which are less than and equal to E2
=COUNTIF(Sheet1!D2:D13,"<="&E2)

but i want this same thing to be used in vba so i used this function
Application.WorksheetFunction.CountIf(rng, Range("<=" & "E2"))

but it showing error of type mismatch

help me out with this
Untested (about to go to sleep), but I think it should be this way...

Application.WorksheetFunction.CountIf(rng, "<=" & Range("E2"))

Of course, you have to assign this to something in order to preserve the calculated value.
 
Upvote 0
Try

Code:
Sub MM1()
Dim rng As Range, val As Long
Set rng = Sheets("Sheet1").Range("D2:D13")
Val = Application.WorksheetFunction.CountIf(rng, "<=" & Range("E2"))
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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