Reputation: 323
I have a very large Excel workbook (25+ worksheets, 15+ VBA modules) for financial analysis.
I've noticed that one of the formula doesn't display a value until I manually save the workbook 2 - 3 times. Before saving it will appear as a dash (-). After saving 2 - 3 times, the values appear as expected.
I have put in a few ActiveWorkbook.Save
in my macro runs already but they don't seem to affect this case.
The formula in question is (for one cell):
=OFFSET(THIS_CELL, 0, -1)+INDEX('ExternalWorksheet'!$A$1:$CR$300,MATCH("Some Term",'ExternalWorksheet'!$A:$A,0),MATCH($B5,'ExternalWorksheet'!$1:$1,0))+INDEX('ExternalWorksheet'!$A$1:$CR$300,MATCH("Some Other Term",'ExternalWorksheet'!$A:$A,0),MATCH($B5,'ExternalWorksheet'!$1:$1,0))+INDEX('ExternalWorksheet'!$A$1:$CR$300,MATCH("Yet Another Term",'ExternalWorksheet'!$A:$A,0),MATCH($B5,'ExternalWorksheet'!$1:$1,0))-OFFSET(THIS_CELL, 0, -17)
(I know it is unruly, I didn't create it, I'm just the programmer ;) )
I am using the THIS_CELL
trick as described in this other SO post because this formula appears in multiple 'tables' in this worksheet.
My client isn't pleased about having this column appear as dashes and the columns that depend on it appearing as N/A until he saves. From what I can tell, this behaviour is related to the usage of THIS_CELL (or the OFFSET) as if I remove the OFFSET the cells update as expected. However, I can't see how to get rid of it as I have to repeat this formula over multiple 'tables' in the worksheet and have them reference the correct cells. I also can't switch to RC notation as my client doesn't like it.
Upvotes: 1
Views: 2338
Reputation: 323
I did a comparsion between CTRL+S save and a ActiveWorkbook.Save
and in this case they do work differently. No matter how many times I save via VBA it wouldn't update the formulae. CTRL+S appears to be forcing a re-calculation.
From this post I added in
ActiveSheet.EnableCalculation = False
ActiveSheet.EnableCalculation = True
prior to saving and that has solved the problem.
Upvotes: 0
Reputation:
You can modify THIS_CELL trickery to remove dependency on the OFFSET
function altogether by changing the initial selected cell to produce the offset necessary. The reason that the first step in those directions states select cell A1 (this is important!) is so THIS_CELL always refers to the cell you selected. You don't want the cell that you selected. You want the one either 1 or 17 columns to the left.
(stolen and modified from Create a named formula called THIS_CELL)
=!Q1
NOTE: Be sure cell R1 is selected. This formula is relative to the ActiveCell.
Under Scope: select Workbook.
Click OK.
Repeat using the name THE_CELL_WAY_BEHIND_ME and =!A1
for refers to.
Close the Name Manager.
Using =THE_CELL_BEHIND_ME
is the same as =OFFSET(THIS_CELL, 0, -1)
and =THE_CELL_WAY_BEHIND_ME
is the same as =OFFSET(THIS_CELL, 0, -17)
.
Upvotes: 1