I have a range of cells with color/font formatting and I used the VBA below to sum the cells based on formatting, Great!. But know I want to take these same formatted cells and replace any value with a text string. Can't figure it out
Function SumIFbyColor(rColor As Range, rCells As Range)
'Parameter rColor is used for a cell from your worksheet
'formatted with the same color like color desired from the table.
'Parameter rCells is used for a cell range from your worksheet
'that can contain cells formatted with the same color of font or background
'like referenced cell.
'Defining variables
Dim rRange As Range
Dim sumColor As Long
'Initiating sumColor
sumColor = 0
' Parsing cells from range
For Each rRange In rCells
If rRange.Font.Color = rColor.Font.Color Or rRange.Interior.Color = rColor.Interior.Color Then
sumColor = sumColor + rRange.Cells.Value
End If
Next rRange
' Return results
SumIFbyColor = sumColor
End Function











LinkBack URL
About LinkBacks

Register To Reply

Bookmarks