VB Problem with COUNTIF

yensid00

New Member
Joined
May 28, 2008
Messages
30
I am fairly new to the world of VB and am having a problem that I can't seem to figure out.

I have a large data file that changes in size and number on a daily basis. I have three columns that contains a numerical amount that I sum up and then a series of columns with text where I am trying to count the number of times an "X" appears. I then get the sum of the numerical and text columns together. I was originally using a formula with COUNTA for the text section but discovered that since the info is coming from a .CSV file that there is hidden text that is being counted and returning an incorrect number. Here is my original code:
Code:
ActiveCell.FormulaR1C1 = "=SUM(RC[8]:RC[10])+COUNTA(RC[11]:RC[25])"

I tried changing it to a COUNTIF so that it will only return the amount of spaces containing an "X" but the new code always gives an error that says:
HTML:
Compile error: Unexpected: end of statement

The new formula I am attempting to use is:
Code:
ActiveCell.FormulaR1C1 = "=SUM(RC[8]:RC[10])+COUNTIF(RC[11]:RC[25],"X")"

What am I doing wrong???
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Jonmo1

MrExcel MVP
Joined
Oct 12, 2006
Messages
44,061
when the formula you want entered into the cell contains quotes, you have to double up the quotes in the VBA code...

try

veCell.FormulaR1C1 = "=SUM(RC[8]:RC[10])+COUNTIF(RC[11]:RC[25],""X"")"

Hope that helps..
 
Upvote 0

twistinginthewind

Board Regular
Joined
Jun 25, 2003
Messages
119
Looks like your quotes are entered correctly try this...

ActiveCell.FormulaR1C1 = "=SUM(RC[8]:RC[10])+COUNTIF(RC[11]:RC[25],""X"")"
 
Upvote 0

schielrn

Well-known Member
Joined
Apr 4, 2007
Messages
6,941
It doesn't like your quotes. Maybe try:

Code:
ActiveCell.FormulaR1C1 = "=SUM(RC[8]:RC[10])+COUNTIF(RC[11]:RC[25]," & """ & "X" & """ & ")"
Or if that doesn't work maybe try:
Code:
dim wordX as string
wordX = "X"
ActiveCell.FormulaR1C1 = "=SUM(RC[8]:RC[10])+COUNTIF(RC[11]:RC[25]," & wordX & ")"
Quotes are always wierd in VBA.
 
Upvote 0

Forum statistics

Threads
1,190,825
Messages
5,983,106
Members
439,824
Latest member
nellyc

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