Countif in VBA

Fredek

Board Regular
Joined
Mar 8, 2011
Messages
65
Hi guys,

I have a named table ACR_tbl, I would like to count all the times #N/A appear in the table. If the number is greater than 0 I would like to pull up a MsgBox as a warning.

At the moment I am doing this (to an extent with COUNTIF(ACR_tbl,NA()) ), is there a simple way to do it via VBA?
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Hi Joe, thank you for the link!

I would like to use:
Code:
'NumberOfNAsOnly = Application.CountIf(Columns("O"), "#N/A")

How can I replace columns("O") with my ACR_tbl? I tried something like ActiveSheet.ListObjects("ACR_tbl").DataBodyRange but it doesn't work, any idea?
 
Upvote 0
I don't work much with tables, but why not just enter the columns that the tables uses in there?
 
Upvote 0
Hi Joe,

I will give it a try! How can I specify the sheet I want it to look? I need it to look in columns A-D.

Code:
NumberOfNAsOnly = Application.CountIf(Worksheets("ACR Ratings").Columns(D), "#N/A")

I'm getting an object defined error, any ideas?
 
Upvote 0
Sorry, I have been away for a few days.
Try this:
Code:
Set MyRange = Worksheets("ACR Ratings").Columns("D:D")
NumberOfNAsOnly = Application.CountIf(MyRange, "#N/A")
 
Upvote 0

Forum statistics

Threads
1,215,523
Messages
6,125,318
Members
449,218
Latest member
Excel Master

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