Forum Discussion
JoeCavasin
Jan 18, 2025Brass Contributor
Adding COUNTIF formula to cell by VBA code
Morning all, need some assistance. Attempting to insert a new formula by VBA with an already working Macro. All the other references unhighlighted below work perfectly, but I am missing something with the syntax around a countif function.
The countif currently works on the excel sheet itself, however adding it into the VBA is generating the typical "Compile error: expected: end of statement" error indicating a syntax problem. Any advice?
Quotes inside a quoted string must be doubled:
.Range("AH11").Formula = "=COUNTIF($B11:$AF11, ""B"")"
- JoeCavasinBrass Contributor
As always, thanks Hans. Swear i tried that, but likely tried '"B"' instead, and regardless didn't come to the right solution.
Quotes inside a quoted string must be doubled:
.Range("AH11").Formula = "=COUNTIF($B11:$AF11, ""B"")"