Issues with formulae in VBA

Carty

Board Regular
Joined
Mar 3, 2009
Messages
76
Hello.

I would like some help to understand an issue I'm having trying to use VBA to write a formula.

In workbookA, worksheetC, cell E31 I have a formula that references worksheetC B9 and 3 columns in worksheetB. It looks like this:

"("&TEXT(INDEX('worksheetB'!$G$1:$G$65552,MATCH(VALUE(MID($B$9,4,5)),'worksheetB'!$O$1:$O$65552,)),"0.0E+00")&"-"&TEXT(INDEX('worksheetB'!$K$1:$K$65552,MATCH(VALUE(MID($B$9,4,5)),'worksheetB'!$O$1:$O$65552,)),"0.0E+00")&")"
and the result is this:
(1.2E+03 - 2.4E+03)

If I copy this formula into workbookB worksheetC cell E31(which looks exactly like worksheetC on workbookA and B9 has the same value) and close workbookA [workbookA.xlsm] is inserted between ' and worksheet. The result is the same

In workbookA I write

Code:
[COLOR=#222222][FONT=Verdana]Workbooks.open(“workbookB”)[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana]Sheets("SheetC").cells(31, 5).formulaR1C1 ="=""(""&TEXT(INDEX('[WorkbookA.XLSM]worksheetB'!R1C7:R65552C7,MATCH(VALUE(MID(R9C2,4,5)),'[WorkbookA.XLSM]worksheetB'!R1C15:R65552C15,)),""0.0E+00"")&""- ""&TEXT(INDEX('[WorkbookA.XLSM]worksheetB'!R1C11:R65552C11,MATCH(VALUE(MID(R9C2,4,5)),'[WorkbookA.XLSM]worksheetB'!R65552C15,)),""0.0E+00"")&"")"""[/FONT][/COLOR]
An application or object defined error runtime 1004occurs

Also, as the formula is quite long, it goes across 3 pagewidths!

When I have written long lines of code before I have used “_”to break the code up and display it on 1 page width but this throws up an end of statement compile error.

I have probably done something stupid but cannot see where.

Paul
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

Forum statistics

Threads
1,215,601
Messages
6,125,763
Members
449,259
Latest member
rehanahmadawan

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