Excel formula doesn't work when recorded as macro - syntax error

Welldonedav

New Member
Joined
Dec 18, 2013
Messages
5
hi,

i have a formula that works in excel but when i come to record it as a macro it no longer works and si ignored but doesn't diurupt any other part of the macro. Recording below

Range("O3").Select
ActiveCell.FormulaR1C1 = _
"=IF(OR(RC[-9]=""TY"",RC[-9]=""1M"",RC[-9]=""2M"",RC[-9]=""3M"",RC[-9]=""5M""),CONCATENATE(TRIM(RC[-7])/10,TRIM(RC[-8])),CONCATENATE(TRIM(RC[-7]),TRIM(RC[-8])))"


When i finish recording it shows a syntax error but shows the correct result in the square on excel.

When the macro is run the result is always the IF false outcome even if the IF is TRUE.

I would greatly appreciate anyones help/advice on this as i'm pretty new to vba

thanks
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
What do you have in H3, F3 and G3?

By the way, your formula could be condensed to:
=TRIM(H3)/IF(OR(F3={"TY","1M","3M","5M"}),10,1)&TRIM(G3)
 
Upvote 0
in H3,F3 and G3 there are product codes and expiry details which I am trying to concatenate.

thanks for the condensed formula, where would I input that it to the code? it doesn't seem to work if I just substitute it for what i already have. apoloiges if these are v.basic questions
 
Upvote 0
in H3,F3 and G3 there are product codes and expiry details which I am trying to concatenate.

thanks for the condensed formula, where would I input that it to the code? it doesn't seem to work if I just substitute it for what i already have. apoloiges if these are v.basic questions

What values are in the 3 cells the formula refers to?
The formula I posted was the Excel version of your VBA formula. The VBA version would be (note that you don't need to select a cell to write a formula to it):

Code:
Range("O3").FormulaR1C1 = "=TRIM(RC[-7])/IF(OR(RC[-9]={""TY"",""1M"",""3M"",""5M""}),10,1)&TRIM(RC[-8])"
 
Upvote 0
Market</SPAN>B/S</SPAN>Volume</SPAN> Expiry</SPAN>Contract</SPAN>C/P</SPAN>Strike</SPAN>Price</SPAN>AVG Price</SPAN>
Trade Details</SPAN>CME</SPAN>S</SPAN>100</SPAN> DEC3</SPAN> ES</SPAN> P</SPAN>1700</SPAN>0.55</SPAN>
CBOT</SPAN>S</SPAN>100</SPAN> DEC3</SPAN> TY3</SPAN> P</SPAN>1235</SPAN>0.07</SPAN>
CBOT</SPAN>S</SPAN>100</SPAN> DEC3</SPAN> TY3</SPAN> P</SPAN>1220</SPAN>0.01</SPAN>
CBOT</SPAN>B</SPAN>200</SPAN> DEC3</SPAN> TY3</SPAN> P</SPAN>1225</SPAN>0.01</SPAN>

<TBODY>
</TBODY><COLGROUP><COL span=10></COLGROUP>
 
Upvote 0
i adjust the expiry and and product codes earlier in the macro so F3 which is Contract changes, TY3 becomes 3M which should trigger a change in the way G3 and H3 then contatenate as the strike price should become 123.5, 122, and 122.5 respectively....
 
Upvote 0

Forum statistics

Threads
1,215,432
Messages
6,124,856
Members
449,194
Latest member
HellScout

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