VBA formula, "D" in the cell, so Count if is ""D"", but thats an error

Tinkerz

Board Regular
Joined
Feb 26, 2007
Messages
179
Hi

Worksheets("Calculations").Range("C5").Offset(0, offsetcounter) = Application.WorksheetFunction.CountIf(Worksheets(wsnew.Name).Range("R:R"), ""D"")

I am trying to do a CountIf statement, the criterea is "D", thats in the Cell, this is a download so I cant change it, is there a simple workaround, because I need to write in the Countif statement ""D"" for it to be seen as a string "D" wont find the Counts.

Thanks
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
In this application, I don't believe you need the duplicated speech marks around the D, which you probably would if you were inserting the formula into a cell.

Application.WorksheetFunction.CountIf(Worksheets(wsnew.Name).Range("R:R"), "D")
 
Upvote 0
The Cells in the range contains "D", not D

so the critera for the formula need to be ""D"", to register as a string in the countif critera

Thanks
 
Upvote 0
Believe it or not, you need TRIPLE quotes

Application.WorksheetFunction.CountIf(Worksheets(wsnew.Name).Range("R:R"), """D""")
 
Upvote 0
Just a sidenote, this is redundant
Worksheets(wsnew.Name).Range("R:R")

The whole purpose of creating a worksheet object is to avoid having to use
Worksheets("name")...

This will suffice
wsnew.Range("R:R")
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,740
Members
452,940
Latest member
rootytrip

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