.Formula Find Compile error

MrBuzz

New Member
Joined
Apr 17, 2021
Messages
2
Office Version
  1. 2007
Platform
  1. Windows
I am trying to have a macro put a formula into Cell J10 that contains the Excel Find function and I get get an "expected end of statement" compile error. The formula works if I manually enter it into a cell on the spreadsheet.

Cell F10 contains +123.45 USDC I want to parse out the number which can vary in length. While writing the macro VBA highlights the U and says expected end of statement. I saw the post about adding spaces which I tried with no improvement. I thought VBA would just look at the formula within the parentheses as a string of text so I am confused as to why it is trying to compile the code as a command.

RANGE("J10") . formula = "=IF(F10<>"",VALUE(LEFT(F10,FIND( "U" , F10 )-1)),"")"

I get the same error with this simpler code: RANGE("J10").Formula = "=FIND("U",F10)"

Any help appreciated. Thanks for your time.
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
When inserting formulae into a sheet using VBA, ALL quotes need to be double quotes
VBA Code:
Range("J10").Formula = "=IF(F10<>"""",VALUE(LEFT(F10,FIND( ""U"" , F10 )-1)),"""")"
 
Upvote 0
When inserting formulae into a sheet using VBA, ALL quotes need to be double quotes
VBA Code:
Range("J10").Formula = "=IF(F10<>"""",VALUE(LEFT(F10,FIND( ""U"" , F10 )-1)),"""")"
Thanks Michael. I had tried doubling some of the quotes but not all of them. I downloaded the XL2BB file and will read it in the next couple of days. Cheers
 
Upvote 0

Forum statistics

Threads
1,214,382
Messages
6,119,194
Members
448,874
Latest member
Lancelots

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