Soldato
- Joined
- 14 Nov 2002
- Posts
- 7,770
- Location
- Under the Hill
I have the following macro, but am having a problem in getting it to auto update my calculations in excel. I have to manually click on the cell and hit enter after making changes to my worksheet to get it to update. Does anybody know what I can add to the code to fix this? I am new to VB so am just learning the ropes.
Thanks
Function ColorFunction(rColor As Range, rRange As Range, Optional SUM As Boolean)
Dim rCell As Range
Dim lCol As Long
Dim vResult
'Sums or counts cells based on a specified fill color.
''''''''''''''''''''''''''''''''''''''...
lCol = rColor.Interior.ColorIndex
If SUM = True Then
For Each rCell In rRange
If rCell.Interior.ColorIndex = lCol Then
vResult = WorksheetFunction.SUM(rCell, vResult)
End If
Next rCell
Else
For Each rCell In rRange
If rCell.Interior.ColorIndex = lCol Then
vResult = 1 + vResult
End If
Next rCell
End If
ColorFunction = vResult
End Function
Thanks

Function ColorFunction(rColor As Range, rRange As Range, Optional SUM As Boolean)
Dim rCell As Range
Dim lCol As Long
Dim vResult
'Sums or counts cells based on a specified fill color.
''''''''''''''''''''''''''''''''''''''...
lCol = rColor.Interior.ColorIndex
If SUM = True Then
For Each rCell In rRange
If rCell.Interior.ColorIndex = lCol Then
vResult = WorksheetFunction.SUM(rCell, vResult)
End If
Next rCell
Else
For Each rCell In rRange
If rCell.Interior.ColorIndex = lCol Then
vResult = 1 + vResult
End If
Next rCell
End If
ColorFunction = vResult
End Function