hvaleagues
New Member
- Joined
- Sep 25, 2009
- Messages
- 9
I have a Macro causing slow calculation in my workbook. File size is only 2.6 mb. If I run it without macros it calculates quickly. If I enable macros, it is slow as can be. The macro I run is to sum coloured cells and is as follows.
Is there something in this code that slows down my calculations? Is there another more efficient way of doing it?
I have rows with cells that are shaded either rose or green. I need to be able to have 3 totals per row, one totals all the cells, the second totals the rose shaded cells and the last totals the green shaded cells. The code above works, however it really slows down all calculations.
Any insight would be greatly appreciated, as I a new to macros.
Code:
Function SumColoured(oRange As Range, lColorIndex As Variant) As Variant
Dim oCell As Range
Dim oArea As Range
Dim dSum As Double
Application.Volatile
For Each oArea In oRange.Areas
For Each oCell In oRange.Cells
If oCell.Interior.ColorIndex = lColorIndex Then
dSum = dSum + Val(oCell.Value)
End If
Next
Next
SumColoured = dSum
End Function
Is there something in this code that slows down my calculations? Is there another more efficient way of doing it?
I have rows with cells that are shaded either rose or green. I need to be able to have 3 totals per row, one totals all the cells, the second totals the rose shaded cells and the last totals the green shaded cells. The code above works, however it really slows down all calculations.
Any insight would be greatly appreciated, as I a new to macros.