HELP! Sum rows that contain letters

mesa

New Member
Joined
Dec 16, 2009
Messages
12
Hello,

I run a football pick'em league and I need to find a way to sum rows that contain letters. So below is a jpg of my spreadsheet with the sum would come out to 136, but at times I make mistakes and enter the same number twice in a row. So if I had a formula that would sum the numbers in the row and the sum was different than 136 I can find where I made a mistake. The first row would sum the numbers through B2 to Q2 and equal 136. Thank in advance!

Example:
2009NFLSeason.jpg
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
You need to paste this into a general module in your workbook:

Code:
Function ColorIndexOfRange(InRange As Range, _
        Optional OfText As Boolean = False, _
        Optional DefaultColorIndex As Long = -1) As Variant
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' ColorIndexFromRange
    ' This function returns an array of values, each of which is
    ' the ColorIndex of a cell in InRange. If InRange contains both
    ' multiple rows and multiple columns, the array is two dimensional,
    ' number of rows x number of columns. If InRange is either a single
    ' row or a single column, the array is single dimensional. If
    ' InRange has multiple rows, the array is transposed before
    ' returning it. The DefaultColorIndex indicates what color
    ' index to value to substitute for xlColorIndexNone and
    ' xlColorIndexAutomatic. If OfText is True, the ColorIndex
    ' of the cell's Font property is returned. If OfText is False
    ' or omitted, the ColorIndex of the cell's Interior property
    ' is returned.
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    
    Dim Arr() As Long
    Dim NumRows As Long
    Dim NumCols As Long
    Dim RowNdx As Long
    Dim ColNdx As Long
    Dim CI As Long
    Dim Trans As Boolean
    
    Application.Volatile True
    If InRange Is Nothing Then
        ColorIndexOfRange = CVErr(xlErrRef)
        Exit Function
    End If
    If InRange.Areas.Count > 1 Then
        ColorIndexOfRange = CVErr(xlErrRef)
        Exit Function
    End If
    If (DefaultColorIndex < -1) Or (DefaultColorIndex > 56) Then
        ColorIndexOfRange = CVErr(xlErrValue)
        Exit Function
    End If
    
    NumRows = InRange.Rows.Count
    NumCols = InRange.Columns.Count
    
    If (NumRows > 1) And (NumCols > 1) Then
        ReDim Arr(1 To NumRows, 1 To NumCols)
        For RowNdx = 1 To NumRows
            For ColNdx = 1 To NumCols
                CI = ColorIndexOfOneCell(Cell:=InRange(RowNdx, ColNdx), _
                    OfText:=OfText, DefaultColorIndex:=DefaultColorIndex)
                Arr(RowNdx, ColNdx) = CI
            Next ColNdx
        Next RowNdx
        Trans = False
    ElseIf NumRows > 1 Then
        ReDim Arr(1 To NumRows)
        For RowNdx = 1 To NumRows
            CI = ColorIndexOfOneCell(Cell:=InRange.Cells(RowNdx, 1), _
                OfText:=OfText, DefaultColorIndex:=DefaultColorIndex)
            Arr(RowNdx) = CI
        Next RowNdx
        Trans = True
    Else
        ReDim Arr(1 To NumCols)
        For ColNdx = 1 To NumCols
            CI = ColorIndexOfOneCell(Cell:=InRange.Cells(1, ColNdx), _
                OfText:=OfText, DefaultColorIndex:=DefaultColorIndex)
            Arr(ColNdx) = CI
        Next ColNdx
        Trans = False
    End If
    If IsObject(Application.Caller) = False Then
        Trans = False
    End If
    
    If Trans = False Then
        ColorIndexOfRange = Arr
    Else
        ColorIndexOfRange = Application.Transpose(Arr)
    End If
    
End Function
 Function ColorIndexOfOneCell(Cell As Range, OfText As Boolean, _
        DefaultColorIndex As Long) As Long
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' ColorIndexOfOneCell
    ' This returns the ColorIndex of the cell referenced by Cell.
    ' If Cell refers to more than one cell, only Cell(1,1) is
    ' tested. If OfText True, the ColorIndex of the Font property is
    ' returned. If OfText is False, the ColorIndex of the Interior
    ' property is returned. If DefaultColorIndex is >= 0, this
    ' value is returned if the ColorIndex is either xlColorIndexNone
    ' or xlColorIndexAutomatic.
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Dim CI As Long
    
    Application.Volatile True
    If OfText = True Then
        CI = Cell(1, 1).Font.ColorIndex
    Else
        CI = Cell(1, 1).Interior.ColorIndex
    End If
    If CI < 0 Then
        If IsValidColorIndex(ColorIndex:=DefaultColorIndex) = True Then
            CI = DefaultColorIndex
        Else
            CI = -1
        End If
    End If
    
    ColorIndexOfOneCell = CI
    
End Function
Private Function IsValidColorIndex(ColorIndex As Long) As Boolean
    Select Case ColorIndex
        Case 1 To 56
            IsValidColorIndex = True
        Case xlColorIndexAutomatic, xlColorIndexNone
            IsValidColorIndex = True
        Case Else
            IsValidColorIndex = False
    End Select
End Function
 
Upvote 0
Still didn't work. FYI I'm using a Mac version of excel, not sure if that makes a difference.

I would be happy to send the excel file via email of anyone is interested in giving it a shot.

johnso52@hotmail.com
 
Last edited:
Upvote 0
If your Excel version supports VBA the function should work. What did you do with the code I posted and in what way doesn't the formula work?
 
Upvote 0
If your Excel version supports VBA the function should work. What did you do with the code I posted and in what way doesn't the formula work?

Brought up VBA (alt F11) then pasted the code you gave me into "ThisWorkBook" (general). Once I do that (Declarations) are added: ColorIndexOfOneCell, ColorIndexOfRange and IsValidColorIndex.

I still get the #name? error.

Also, after the code is pasted and I reopen Excel I receive two messages before I can work. "Workbook your are opening contains macros" options are to Enable/Do not open/Disable. I enable and proceed.

Another message after the macros are enabled "Microsoft Excel cannot calculate a formula"

FYI - I tired this both on my PC and Mac and receive the same result. Also I have 17 sheets within my workbook (17 weeks of the NFL schedule)
 
Last edited:
Upvote 0
You need to put the code in a General module (eg Module1), not the ThisWorkbook module. In the Visual Basic Editor select your workbook in the Project Window and choose Insert|Module. Paste the code into the window on the right.
 
Upvote 0
You need to put the code in a General module (eg Module1), not the ThisWorkbook module. In the Visual Basic Editor select your workbook in the Project Window and choose Insert|Module. Paste the code into the window on the right.
OK that worked. Thought I might have been putting it in the wrong place :confused:

But the total still comes out to 136 no matter what color I change the cells font to.

Would CountColor work instead of ColorIndexOfRange?
 
Upvote 0
Also after the change I can no longer open the Excel file when I enable macros, says Excel has encountered a problem and must shutdown. Good thing I did a save as before trying all of this ...lol
 
Upvote 0
If you have coloured the font:

=SUMPRODUCT(--(ColorIndexOfRange(B2:Q2,TRUE)<>3),--(MID(B2:Q2,FIND(" ",B2:Q2)+1,255)))
 
Upvote 0
Andrew,
Thank you so much for your help! My league is much easier to run now that I can catch errors with the formulas.

Thanks again, Merry Christmas and Happy New Year!

Steven
 
Upvote 0

Forum statistics

Threads
1,215,647
Messages
6,126,005
Members
449,279
Latest member
Faraz5023

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top