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

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
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
Looks like your quotes are entered correctly try this...

ActiveCell.FormulaR1C1 = "=SUM(RC[8]:RC[10])+COUNTIF(RC[11]:RC[25],""X"")"
 
Upvote 0
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,214,590
Messages
6,120,423
Members
448,961
Latest member
nzskater

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