Trouble using formula in Excel VBA

dougdrex

Board Regular
Joined
Sep 27, 2013
Messages
79
I'm using Excel 2010 VBA. Here is the issue I'm facing.

I would like to insert a formula into cell Q2 and copy it down to the rest of the rows in that column (number of rows will vary). Here is the code I have, but I keep getting a syntax error. I don't why for sure, but I suspect it has to do with the "{" and "}" symbols in the formula. Can anyone confirm and suggest a workaround?

Code:
Range("Q2).Formula = "=SUM(COUNTIF(P2,{"Account*No Debits",_    "Account*No Credits","Account*Dormant","Whereabouts Unknown",_
    "Cheque*Used","Cheque*not Found","Account*Blocked","Account*Frozen",_
    "Payment involving crisis related customer or institution. Do you want to proceed ?", _
    "Cheque missing or Account mismatch"}))>0"
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Instead of:

"Account*No Debits"
you need:

""Account*No Debits""

and so on.
 
Upvote 0
You had me thinking i was going mad for a minute there. You missed the quote after Q2... Anyway try like this:

Code:
Range("Q2").Formula = "=SUM(COUNTIF(P2,{""Account*No Debits"",""Account*No Credits"",""Account*Dormant""," & _
    """Whereabouts Unknown"",""Cheque*Used"",""Cheque*not Found"",""Account*Blocked""," & _
    """Account*Frozen"",""Payment involving crisis related customer or institution. Do you want to proceed ?""," & _
    """Cheque missing or Account mismatch""}))>0"
 
Upvote 0
You had me thinking i was going mad for a minute there. You missed the quote after Q2... Anyway try like this:

Code:
Range("Q2").Formula = "=SUM(COUNTIF(P2,{""Account*No Debits"",""Account*No Credits"",""Account*Dormant""," & _
    """Whereabouts Unknown"",""Cheque*Used"",""Cheque*not Found"",""Account*Blocked""," & _
    """Account*Frozen"",""Payment involving crisis related customer or institution. Do you want to proceed ?""," & _
    """Cheque missing or Account mismatch""}))>0"

Thank you, that worked perfectly! :)

I can't believe I missed the quote mark after Q2! :( It's the smallest of details that usually causes the biggest of problems.
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,160
Members
453,021
Latest member
Justyna P

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