I have searched on the web quite extensively, but have not managed to find any similar experiences. Any ideas?
I have a simple subroutine in VBA that changes a control cell. This control cell is used by the formulae in another sheet. As the code changes the control values, Excel uses increasingly more and more ram to the point that excel comes to a halt.
Basically I have a sheet setup that has 3000 rows and 330 columns. In each cell of the sheet the same formula below is populated:
=sum(sheet1!F8:INDEX(sheet1!F8:F$3000,Control!$D$1))
So in cells A1
you would have the formula above and in cell say B1
you would have:
=sum(sheet1!F**9**:INDEX(sheet1!F9:F$3000,Control!$D$1))
The control value that the code changes is Control!$D$1
and therefore changing control say from 2 to 4 will result in calculating running Sums from 2 to 4 consecutive rows in sheet1.
Note the code starts by setting a high value in the control cell (200) and works its way down to 2. The memory usage increase is therefore really baffling me.
The code I have is:
For i = 200 To 1 Step -1
Application.Calculation = xlCalculationManual
ClearClipboard 'sets cutcopymode to false
Range("Control!d1").Value = i
Application.Calculation = xlCalculationAutomatic
Next i
Finally I have tried the following alternatives and none of them suited me:
- Doing all calculations in VBA arrays: Since VBA is not multithreaded, this is painfully slow (the point is to take advantage of my cpu cores using formulae in excel worksheets)
- Setting screenupdating = false, enablevents = false, cutcopymode = false have no significant improvements
- Converting formulae to values and reentering formulae by VBA: It again slows down the calculations
- Manually reducing the number of processors: Defeats the purpose of my method as I need fast calculations
Is this an excel bug?