VisaManiac
Technical User
I hope I'm posting this in the correct place. I've done some research and everyone is pointing me to use VBA for my excel funtion I'm searching for.
I have on column C my dollar values, and D ~ O are months Jan ~ Dec. In those monthly columns no value will be input, just blue colored cells, however I'd like for the bottom of each column to only give me the SUM pulled from column C where the color blue reside. For example...
| C | D | E |
$10 blue
$20 blue
$30 blue
$40 blue
TOTAL =40 =60
I've found several tutorials on how to do this, but I don't know VBA at all, so I didn't know how to make the code reference the correct cells or know what color to find. Here's one that seems relevant to what I'm looking for, I just am clueless how to change it around to fit my cell structure...
Function SumIfByColor(InRange As Range, _
WhatColorIndex As Integer, SumRange As Range, _
Optional OfText As Boolean = False) As Variant
'
' This function will return the SUM of the values of cells in
' SumRange where the corresponding cell in InRange has a background
' color (or font color, if OfText is true) equal to WhatColorIndex.
'
Dim OK As Boolean
Dim Ndx As Long
Application.Volatile True
If (InRange.Rows.Count <> SumRange.Rows.Count) Or _
(InRange.Columns.Count <> SumRange.Columns.Count) Then
SumIfByColor = CVErr(xlErrRef)
Exit Function
End If
For Ndx = 1 To InRange.Cells.Count
If OfText = True Then
OK = (InRange.Cells(Ndx).Font.ColorIndex = WhatColorIndex)
Else
OK = (InRange.Cells(Ndx).Interior.ColorIndex = WhatColorIndex)
End If
If OK And IsNumeric(SumRange.Cells(Ndx).Value) Then
SumIfByColor = SumIfByColor + SumRange.Cells(Ndx).Value
End If
Next Ndx
End Function
To call this function from a worksheet cell with a formula use
=SUMIFBYCOLOR(A1:A10,3,B1:B10,FALSE)
Any guidance on this would be greatly appreciated!!
I have on column C my dollar values, and D ~ O are months Jan ~ Dec. In those monthly columns no value will be input, just blue colored cells, however I'd like for the bottom of each column to only give me the SUM pulled from column C where the color blue reside. For example...
| C | D | E |
$10 blue
$20 blue
$30 blue
$40 blue
TOTAL =40 =60
I've found several tutorials on how to do this, but I don't know VBA at all, so I didn't know how to make the code reference the correct cells or know what color to find. Here's one that seems relevant to what I'm looking for, I just am clueless how to change it around to fit my cell structure...
Function SumIfByColor(InRange As Range, _
WhatColorIndex As Integer, SumRange As Range, _
Optional OfText As Boolean = False) As Variant
'
' This function will return the SUM of the values of cells in
' SumRange where the corresponding cell in InRange has a background
' color (or font color, if OfText is true) equal to WhatColorIndex.
'
Dim OK As Boolean
Dim Ndx As Long
Application.Volatile True
If (InRange.Rows.Count <> SumRange.Rows.Count) Or _
(InRange.Columns.Count <> SumRange.Columns.Count) Then
SumIfByColor = CVErr(xlErrRef)
Exit Function
End If
For Ndx = 1 To InRange.Cells.Count
If OfText = True Then
OK = (InRange.Cells(Ndx).Font.ColorIndex = WhatColorIndex)
Else
OK = (InRange.Cells(Ndx).Interior.ColorIndex = WhatColorIndex)
End If
If OK And IsNumeric(SumRange.Cells(Ndx).Value) Then
SumIfByColor = SumIfByColor + SumRange.Cells(Ndx).Value
End If
Next Ndx
End Function
To call this function from a worksheet cell with a formula use
=SUMIFBYCOLOR(A1:A10,3,B1:B10,FALSE)
Any guidance on this would be greatly appreciated!!