Count instances of "No"

samuel.nunn

New Member
Joined
Feb 22, 2009
Messages
20
Need a Macro (not formula) for the following:

How do I count the instances of the string "No" within the range B2:B65536. Also, I need to store this count as a variable so I can then post the count to another worksheet. Any suggestions?
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
samuel.nunn,

Code:
Option Explicit
Sub CountNo()
Dim NbrOfNo As Long
Dim rng As Range

  Set rng = Range("B2", Range("B" & Rows.Count).End(xlUp))
  
  NbrOfNo = Application.WorksheetFunction.CountIf(rng, "No")
  
  Sheets("Sheet2").Range("A1").Value = Application.WorksheetFunction.CountIf(rng, "No")

End Sub


Have a great day,
Stan
 
Upvote 0
Thanks, jonmo1. Worked great.

Question though, why does it have to be "application"? Why doesn't "worksheet" work?

Thanks,
Sam
 
Upvote 0
Thanks, jonmo1. Worked great.

Question though, why does it have to be "application"? Why doesn't "worksheet" work?

Thanks,
Sam

Because Countif is a function, just like you would write in a cell formula.
It's part of the Excel Application, not the worksheet.

Technically speaking, the full command is

Application.WorksheetFunction.Countif

The worksheetfunction object holds all (well, almost all) the same functions that you can find in writing a formula in a cell.
But it works when you drop the WorksheetFunction and just write Application.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,203,244
Messages
6,054,366
Members
444,719
Latest member
saathvik

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