VBA Code

Chissa

Board Regular
Joined
Sep 27, 2011
Messages
66
Hello there,

Please can someone help me. I am writing a VBA code which I need to include this formula:

"=IF(Allocation!B5="DR",Allocation!D5,-Allocation!D5)"

But for some reason it does not work returns the message "Compile Error: Expected: list or seperator or )"

Allocation is the name of a different worksheet

Thank you very much
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Like this?

Code:
ActiveCell.Formula = "=IF(Allocation!B5=""DR"",Allocation!D5,-Allocation!D5)"

You need to double up the quotes within the formula string so that VBA can parse it.
 
Upvote 0
You need to doouble up the quotes inside the formula like this

Code:
Range("A1").Formula = "=IF(Allocation!B5=""DR"",Allocation!D5,-Allocation!D5)"
 
Upvote 0

Forum statistics

Threads
1,203,171
Messages
6,053,876
Members
444,692
Latest member
Queendom

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