ClimoC
Well-known Member
- Joined
- Aug 21, 2009
- Messages
- 584
Hey all
I have a whizzy lil spreadsheet which 'draws' a scheduling grid based on the table in the same sheet.
Now since the table gets edited manually for changes in scheduling, and new rows and inserted, deleted etc all the time - I've redesigned the drawn grid so that instead of all 15,000 cells (500 rows x 30 cols for days of the month) having a long complex formula in it, the formula is now in a macro which does the calculations on the cell only when requested (and therefor, means the drawn grid never has any errors in it).
My problem is that to do this takes 3:07 each time the macro runs. The actual 'drawing' (conditional formatting) takes the 7secs, calculating the cells takes 3minutes.
This is an unacceptable amount of time for a modern computer to take to do calulations. I understand it's not going to get any faster - but if I change the calculations to vba instead of formulae will it run significantly faster?
here's the macro in full (though the calculation part is only the first section as you'll see)
Will changing the If statement into its vba equivalent speed up this process?
If so, what code will I be using???
Cheers
C
I have a whizzy lil spreadsheet which 'draws' a scheduling grid based on the table in the same sheet.
Now since the table gets edited manually for changes in scheduling, and new rows and inserted, deleted etc all the time - I've redesigned the drawn grid so that instead of all 15,000 cells (500 rows x 30 cols for days of the month) having a long complex formula in it, the formula is now in a macro which does the calculations on the cell only when requested (and therefor, means the drawn grid never has any errors in it).
My problem is that to do this takes 3:07 each time the macro runs. The actual 'drawing' (conditional formatting) takes the 7secs, calculating the cells takes 3minutes.
This is an unacceptable amount of time for a modern computer to take to do calulations. I understand it's not going to get any faster - but if I change the calculations to vba instead of formulae will it run significantly faster?
here's the macro in full (though the calculation part is only the first section as you'll see)
Code:
Sub DrawGrid()
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Set TheGrid = Range("AS6:BW500")
For Each Cell In TheGrid
Cell.FormulaR1C1 = _
"=IF(AND(R5C=RC13,R5C<>RC14),""D/L"",IF(AND(R5C>=RC14,R5C<=RC16),RC19,IF(R5C=RC17,""LC"","""")))"
Application.Calculation = xlCalculationAutomatic
Next
Application.Goto Reference:="R6C45:R500C75"
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Set MyGrid = Range("AS6:BW500")
For Each Cell In MyGrid
If Cell.Value = "" Then
Cell.Interior.ColorIndex = 0
Cell.Font.ColorIndex = 0
End If
If Cell.Value = "D/L" Then
Cell.Interior.ColorIndex = 4
Cell.Font.ColorIndex = 4
End If
If Cell.Value = "LC" Then
Cell.Interior.ColorIndex = 48
Cell.Font.ColorIndex = 48
End If
If Cell.Value <> "" And Cell.Value <> "D/L" And Cell.Value <> "LC" Then
Cell.Interior.ColorIndex = 5
Cell.Font.ColorIndex = 1
End If
Next
Application.Goto Reference:="R6C45:R500C75"
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
Application.Goto Reference:="R6C45:R500C75"
With Selection
.HorizontalAlignment = xlCenter
End With
Range("AS6").Select
Application.ScreenUpdating = True
End Sub
Will changing the If statement into its vba equivalent speed up this process?
If so, what code will I be using???
Cheers
C