Run-time error 1004 with ActiveCell.Formula command

gtdp

New Member
Joined
Dec 10, 2012
Messages
2
Hello everyone! I'm having an incredibly frustrating problem with VBA throwing an application-defined or object-defined error when trying to run the following code (I've cut out some irrelevant bits):

Code:
Dim OriginalPrice As String
OriginalPrice = ActiveCell.Value
Sheets("Calculations").Select
ActiveCell.Formula = "=LEFT(" & OriginalPrice & ",SEARCH(""euro""," & OriginalPrice & ")-2)"

The fourth line is throwing the error. I have a feeling it's got something to do with the OriginalPrice variable being a string, as a couple of lines later I have a similar line:

Code:
ActiveCell.FormulaR1C1 = "=ROUNDUP(" & ConversionFactor & "*Calculations!RC[-1],2)"

which works fine. Additionally, I can replace OriginalPrice (a String) with ConversionFactor (an Integer) in the line of code causing an error, and the error goes away (useful for debugging, but not useful for actually running!) Should I be using a different variable type for inserting variables into ActiveCell.Formula lines when the variable contains letters as well as numbers?

Anyone have any idea how to fix this? Searching around says most people solved the problem by switching from using ActiveCell.Formula to ActiveCell.FormulaR1C1 or vice-versa, but this hasn't solved anything for me. I'd be grateful for any help!
 
Last edited:

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Welcome to MrExcel.

More quotes needed:

ActiveCell.Formula = "=LEFT(""" & OriginalPrice & """,SEARCH(""euro"",""" & OriginalPrice & """)-2)"
 
Upvote 0
Fantastic, that's fixed it completely and it's now working as intended. I'm at a loss as to why those extra quotes are needed, but I'm relieved that it's something relatively easy to fix! Thank you very much for your speedy and concise help, you're a life-saver :)
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

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