I am building a string in code that I then assign to the FormulaR1C1 propery of a cell. The string is a formula that sums the values in a cell across spreadsheets and looks something like this:
=SUM('Sheet1'!Z1,'Sheet2'!Z1...)
The problem is that when I assign it to the FormulaR1C1 property of a cell, that cell shows a #NAME? error and when I check its contents I see that XL has mangled the apostrophes.
Here is what the string looks like as it is assigned to the FormulaR1C1 property, which is what it's supposed to look like:
=SUM('SHEET1'!Z1,'SHEET2'!Z1,'SHEET3'!Z1,'SHEET4'!Z1,'SHEET5'!Z1)
Here is what it looks like after XL mangles it. Notice the apostrophe's are all crazy. Sometimes they properly surround the sheet names as they should and other times they don't, and they always seem to surround the address:
=SUM(SHEET1!'Z1',SHEET2!'Z1',SHEET3!'Z1','SHEET4'!'Z1','SHEET5'!'Z1')
To build the formula, I first loop through the cells on Row 1 of a sheet called UAD2. If the cell contains a formula, then that cell will be changed to hold the new formula I am building. The next step is to loop through the collection of WorkSheets to find all the sheet names that need to be included in the formula. Here is the code that creates the formula:
Please Login or Register to view this content.
Does anyone know what's going on?? Thanks!
Bookmarks