Issues inserting formula into cell via VBA

Range

Board Regular
Joined
Nov 13, 2010
Messages
140
I'm having an expexted end of statement issues trying to insert the below formula into a cell via VBA - any ideas?

ACTUAL FORMULA
Code:
=IF(ISERROR(SEARCH("??:??",A2)),IF(ISERROR(MATCH(TEXT(C1+1/1440,"""*""hh:mm""*"""),A:A,0)),"",C1+1/1440/(MATCH(TEXT(C1+1/1440,"""*""hh:mm""*"""),A:A,0)-MATCH(TEXT(C1,"""*""hh:mm""*"""),A:A,0))),MID(A2,SEARCH("??:??",A2),5)+0)

MY VBA ATTEMPTED CONVERSION
Code:
  ActiveCell.FormulaR1C1 = _       
                "=IF(ISERROR(SEARCH(""??:??"",A2)),IF(ISERROR(MATCH(TEXT(C1+1/1440,""""*"""hh:mm"""*""""),A:A,0)),"""",C1+1/1440/(MATCH(TEXT(C1+1/1440,""""*"""hh:mm"""*""""),A:A,0)-MATCH(TEXT(C1,""""*"""hh:mm"""*""""),A:A,0))),MID(A2,SEARCH(""??:??"",A2),5)+0)"
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
You're not using R1C1, does dropping that from the formula property help?

Otherwise try it without the = in the quotes to see if you can print part of the string


This worked (or at least printed something) when I tried it:

Code:
Sub formpr()
Range("A1").Formula = "=IF(ISERROR(SEARCH(""??:??"",A2)),IF(ISERROR(MATCH(TEXT(C1+1/1440,""""*""hh:mm""*""""),A:A,0)),"""",C1+1/1440/(MATCH(TEXT(C1+1/1440,""""*""hh:mm""*""""),A:A,0)-MATCH(TEXT(C1,""""*""hh:mm""*""""),A:A,0))),MID(A2,SEARCH(""??:??"",A2),5)+0)"
End Sub
 
Last edited:
Upvote 0
It really is quite peculiar indeed.

You're not using R1C1, does dropping that from the formula property help?
Nope - same problem.

Otherwise try it without the = in the quotes to see if you can print part of the string
The string is pasted as value fine but not as a formula. I suspect is has something to do with "hh:mm" which I've amended to ""hh:mm"".... but still getting my brain frazzled.
 
Upvote 0

Forum statistics

Threads
1,214,547
Messages
6,120,139
Members
448,948
Latest member
spamiki

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