Geoff Taylor
Active Member
- Joined
- Dec 11, 2006
- Messages
- 257
I have a large model that manipulates data from multiple sources using all sorts of SUMPRODUCTS, SUMIFS and V/HLOOKUP formulas. It works just fine.
I've written code to automatically generate all the required formulae, sensitive to the size of the data tables and various other factors. The code's logic was to turn off calculation, produce all the formulae and turn calculation back on again, but Excel repeatedly crashed when attempting to calculate the finished model at the end of the routine. However, when I debugged the code line-by-line and forced a calculation every line there was no crash and everything was just dandy.
I've resorted to inserting calculation instructions at a few points during the code and this now works. It's slower than before but at least it doesn't crash, but I'm struggling to understand why this is necessary. Could someone shed some light?
Here's a snippet of the code...
<code>
*SNIP*
With Worksheets("Costings")
sEndColumn = Left(.Range("D13").End(xlToRight).Address,len(.Range("D13").End(xlToRight).Address) - 3)
.Range("D15:" & sEndColumn & "15").FormulaR1C1 = "=IF(ISNA(VLOOKUP(LEFT(R[-2]C,FIND(""/"",R[-2]C)),'Program Code Rules'!R2C3:R73C4,2,FALSE))=TRUE,""??"",VLOOKUP(LEFT(R[-2]C,FIND(""/"",R[-2]C)),'Program Code Rules'!R2C3:R73C4,2,FALSE))"
.Range("D16:" & sEndColumn & "16").FormulaR1C1 = "=VLOOKUP(RIGHT(R[-3]C,1),'Program Code Rules'!R3C8:R8C9,2,FALSE)"
.Range("D20:" & sEndColumn & "20").FormulaR1C1 = "=SUMIF(Banner!R2C19:R50000C19,R13C,Banner!R2C43:R50000C43)"
*SNIP*
</code>
I've written code to automatically generate all the required formulae, sensitive to the size of the data tables and various other factors. The code's logic was to turn off calculation, produce all the formulae and turn calculation back on again, but Excel repeatedly crashed when attempting to calculate the finished model at the end of the routine. However, when I debugged the code line-by-line and forced a calculation every line there was no crash and everything was just dandy.
I've resorted to inserting calculation instructions at a few points during the code and this now works. It's slower than before but at least it doesn't crash, but I'm struggling to understand why this is necessary. Could someone shed some light?
Here's a snippet of the code...
<code>
*SNIP*
With Worksheets("Costings")
sEndColumn = Left(.Range("D13").End(xlToRight).Address,len(.Range("D13").End(xlToRight).Address) - 3)
.Range("D15:" & sEndColumn & "15").FormulaR1C1 = "=IF(ISNA(VLOOKUP(LEFT(R[-2]C,FIND(""/"",R[-2]C)),'Program Code Rules'!R2C3:R73C4,2,FALSE))=TRUE,""??"",VLOOKUP(LEFT(R[-2]C,FIND(""/"",R[-2]C)),'Program Code Rules'!R2C3:R73C4,2,FALSE))"
.Range("D16:" & sEndColumn & "16").FormulaR1C1 = "=VLOOKUP(RIGHT(R[-3]C,1),'Program Code Rules'!R3C8:R8C9,2,FALSE)"
.Range("D20:" & sEndColumn & "20").FormulaR1C1 = "=SUMIF(Banner!R2C19:R50000C19,R13C,Banner!R2C43:R50000C43)"
*SNIP*
</code>