countif blank

itlsbu

Board Regular
Joined
Jul 2, 2002
Messages
102
hello,

I have a macro containing this code
Range("a4").Select
ActiveCell.FormulaR1C1 = "=COUNTIF(R[1]C:R[" & x & "]C," & y & ")"

Where
x = 6
and y = " "

this should result in de formula countif(a5:a10;"") however it doen't

How do I add a blank to this kind of string?

thanx
steven
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

hatman

Well-known Member
Joined
Apr 8, 2005
Messages
2,664
Well, the first tthing I would like to point out is that your message states that y = " "... or, y = [space]. Not a blank, as you state.

another way of getting the blank you expect into the formula might be
Code:
Range("a4").FormulaR1C1 = "=COUNTIF(R[1]C:R[" & x & "]C," & chr(34) & chr(34) & ")"

Though another way is to simply use the appropriate number of quotes to force-feed VBA to get them into the formula (not a big fan of it myself, so I will leave that syntax to others).

Also note that you not need to select a cell to manipulate it... observe the difference between my syntax and yours.
 

itlsbu

Board Regular
Joined
Jul 2, 2002
Messages
102
thank yout very much
worked as expected

I think a tried a zillion ways of putting those quotes in, it never worked...

ps I realize my code can be a lot shorter (more efficient, faster), but what starts as a simple 4-line code, becomes a 4 kilo encyclopedia once a start adding a another great routine...

thanks and cheers Steven
 

Forum statistics

Threads
1,136,926
Messages
5,678,605
Members
419,775
Latest member
joh93

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
Top