Trying to count cells that meet more than one Criteria

suziq729

New Member
Joined
Jul 15, 2005
Messages
8
Help! I have been trying to get a total of cells where they contain "Y" AND have a certain fill color. Nothing I've tried is working. Here are the formulas that have not worked so far. Any ideas??

=COUNT((E9:E491="Y")*(countcolor(B4,E9:E491))*E9:E491)

=COUNT((E9:E491="Y"),((countcolor(B5,E9:E491))))

=COUNT((E9:E491="Y")+((countcolor(B4,E9:E491))))

Thanks...Sue
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
suziq729 said:
Help! I have been trying to get a total of cells where they contain "Y" AND have a certain fill color. Nothing I've tried is working. Here are the formulas that have not worked so far. Any ideas??

=COUNT((E9:E491="Y")*(countcolor(B4,E9:E491))*E9:E491)

=COUNT((E9:E491="Y"),((countcolor(B5,E9:E491))))

=COUNT((E9:E491="Y")+((countcolor(B4,E9:E491))))

Thanks...Sue

Assuming that countcolor exists...

=SUMPRODUCT(--(COUNTCOLOR(B4,E9:E491)+(E9:E491="Y")>0))
 
Upvote 0
That did not work.....does anyone have any other ideas? The formula you posted should have returned a "1" and instead it returned "483"...
 
Upvote 0
suziq729 said:
That did not work.....does anyone have any other ideas? The formula you posted should have returned a "1" and instead it returned "483"...

Care to post the code for COUNTCOLOR before I produce another a non-working formula?
 
Upvote 0
Sub Colors()
End Sub
Function CountColor(ColorRange As Range, Target As Range) As Long
Dim c As Range
For Each c In Target
If c.Interior.ColorIndex = ColorRange.Interior.ColorIndex Then
CountColor = CountColor + 1
End If
Next
End Function
 
Upvote 0
That sub cannot do the job...
ExampleUsesOfHGroveExtCell.xls
BCDEF
3
432
5
6
7
8Items
9Y
10Y
11Y
12N
13Y
14Y
15
suziq729


C4:

=SUMPRODUCT(--(ExtCell("backgroundcolor",E9:E14,1)=B4),--(E9:E14="Y"))

ExtCell's code by Harlan Grove:

Code:
'extension to CELL providing 123 @CELL/@CELLPOINTER functionality as
'well as access to most Range properties
'1st arg determines the property of characteristic being sought
'2nd arg [OPTIONAL] specifies cell reference - AcitveCell if missing
'3rd arg [OPTIONAL] specifies whether to return an array or not
'    True = return array result for .Areas(1)
'    False/missing = return scalar result for .Areas(1).Cells(1, 1)
'
Function ExtCell( _
  prop As String, _
  Optional rng As Variant, _
  Optional rar As Boolean = False _
) As Variant
    'Copyright (C) 2002, Harlan Grove
    'This is free software. It's use in derivative works is covered
    'under the terms of the Free Software Foundation's GPL. See
    'http://www.gnu.org/copyleft/gpl.html

    Dim ws As Worksheet, wb As Workbook, rv As Variant
    Dim i As Long, j As Long, m As Long, n As Long, t As String

    Application.Volatile True

    If TypeOf rng Is Range Then
        If rar Then
            Set rng = rng.Areas(1)
        Else
            Set rng = rng.Areas(1).Cells(1, 1)
        End If
    ElseIf IsMissing(rng) Then
        Set rng = ActiveCell
    Else
        ExtCell = CVErr(xlErrRef)
        Exit Function
    End If
    
    prop = LCase(prop)

    m = rng.rows.Count
    n = rng.Columns.Count
    rv = rng.Value
    
    Set ws = rng.Worksheet
    Set wb = ws.Parent
    
    Select Case prop
    
    Case "across"  'from later 123 versions - limited usefulness!
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = -( _
                      rng.Cells(i, j).HorizontalAlignment = _
                      xlHAlignCenterAcrossSelection _
                    )
                Next j
            Next i
        Else
            rv = -( _
              rng.HorizontalAlignment = _
              xlHAlignCenterAcrossSelection _
            )
        End If
    
    Case "address"  'from CELL - limited usefulness!
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = rng.Cells(i, j).Address
                Next j
            Next i
        Else
            rv = rng.Address
        End If
    
    Case "backgroundcolor"  'from later 123 versions - USEFUL!
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = rng.Cells(i, j).Interior.ColorIndex
                Next j
            Next i
        Else
            rv = rng.Interior.ColorIndex
        End If
    
    Case "bold"  'from later 123 versions - USEFUL!
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = -(rng.Cells(i, j).Font.Bold)
                Next j
            Next i
        Else
            rv = -(rng.Font.Bold)
        End If
        
    
    Case "bottomborder"  'from later 123 versions - USEFUL!
    'Note: many possible return values! wrap inside SIGN to test T/F
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = _
                      rng.Cells(i, j).Borders(xlEdgeBottom).LineStyle - _
                      xlLineStyleNone
                Next j
            Next i
        Else
            rv = rng.Borders(xlEdgeBottom).LineStyle - xlLineStyleNone
        End If
    
    Case "bottombordercolor"  'from later 123 versions - USEFUL!
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = _
                      rng.Cells(i, j).Borders(xlEdgeBottom).ColorIndex
                Next j
            Next i
        Else
            rv = rng.Borders(xlEdgeBottom).ColorIndex
        End If

    Case "col", "column"  'from CELL - pointless - use COLUMN instead!
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = rng.Cells(i, j).Column
                Next j
            Next i
        Else
            rv = rng.Column
        End If

    Case "color"  'from CELL - limited usefulness
    'NOTE: differences between Excel & 123 - Excel's returns 1 whenever
    'there's a color specified for EITHER positive OR negative values
    'in the number format, e.g., 1 for format "[Black]0;-0;0" but not
    'for format "0;-0;[Green]0"
    'Another place where Excel doesn't conform to it's documentation!
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = Evaluate( _
                      "=CELL(""Color""," & _
                      rng.Cells(i, j).Address(True, True, xlA1, True) & _
                      ")" _
                    )
                Next j
            Next i
        Else
            rv = Evaluate( _
              "=CELL(""Color""," & _
              rng.CellsAddress(True, True, xlA1, True) & _
              ")" _
            )
        End If

    Case "columnhidden"
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = rng.Cells(i, j).EntireColumn.Hidden
                Next j
            Next i
        Else
            rv = rng.EntireColumn.Hidden
        End If

    Case "comment"
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    If Not rng.Cells(i, j).Comment Is Nothing Then
                        rv(i, j) = rng.Cells(i, j).Comment.text
                    Else
                        rv(i, j) = ""
                    End If
                Next j
            Next i
        Else
            If Not rng.Comment Is Nothing Then
                rv = rng.Comment.text
            Else
                rv = ""
            End If
        End If

    Case "contents", "value"  'absolutely pointless - compatibility only
        'DOME - nothing more to do!

    Case "coord"  'from later 123 versions - USEFUL!
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = "'" & ws.Name & "'!" & _
                      rng.Cells(i, j).Address
                Next j
            Next i
        Else
            rv = "'" & ws.Name & "'!" & rng.Address
        End If

    Case "currentarray"  'NOTE: returns Range addresses!
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = rng.Cells(i, j).CurrentArray.Address
                Next j
            Next i
        Else
            rv = rng.CurrentArray.Address
        End If

    Case "currentregion"  'NOTE: returns Range addresses!
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = rng.Cells(i, j).CurrentRegion.Address
                Next j
            Next i
        Else
            rv = rng.CurrentRegion.Address
        End If

    'different characteristics grouped for efficiency
    'TYPE needed for backward compatibility w/123 but otherwise useless
    'DATATYPE and FORMULATYPE are options in later 123 versions' @CELL
    'no need for them but included to make 123 conversion easier
    Case "datatype", "formulatype", "type"
        t = Left(prop, 1)
        
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = IIf( _
                      t = "f" And rng.Cells(i, j).HasFormula, _
                      "f", _
                      "" _
                    )
                    
                    If rng.Cells(i, j).formula = "" Then
                        rv(i, j) = rv(i, j) & "b"
                    ElseIf IsNumeric("0" & CStr(rng.Cells(i, j).Value)) _
                      Or (t = "t" And IsError(rng.Cells(i, j).Value)) Then
                        rv(i, j) = rv(i, j) & "v"
                    ElseIf rng.Cells(i, j).Value = CVErr(xlErrNA) Then
                        rv(i, j) = rv(i, j) & "n"
                    ElseIf IsError(rng.Cells(i, j).Value) Then
                        rv(i, j) = rv(i, j) & "e"
                    Else
                        rv(i, j) = rv(i, j) & "l"
                    End If
                Next j
            Next i
        Else
            rv = IIf( _
              t = "f" And rng.HasFormula, _
              "f", _
              "" _
            )

            If rng.formula = "" Then
                rv = rv & "b"
            ElseIf IsNumeric("0" & CStr(rng.Value)) _
              Or (t = "t" And IsError(rng.Value)) Then
                rv = rv & "v"
            ElseIf rng.Value = CVErr(xlErrNA) Then
                rv = rv & "n"
            ElseIf IsError(rng.Value) Then
                rv = rv & "e"
            Else
                rv = rv & "l"
            End If
        End If

    Case "filedate"  'from later 123 versions - limited usefulness!
        t = wb.BuiltinDocumentProperties("Last Save Time")  'invariant!

        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = t
                Next j
            Next i
        Else
            rv = t
        End If

    Case "filename"  'from CELL - limited usefulness!
    'A testament to Microsoft's hypocracy! They could include this from
    '123R2.2 (it wasn't in 123R2.0x), modify it in Excel 4.0 to include
    'the worksheet name, but they can't make any other changes to CELL?!
        t = Evaluate( _
          "=CELL(""Filename""," & _
          rng.Address(True, True, xlA1, True) & _
          ")" _
        )  'invariant!

        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = t
                Next j
            Next i
        Else
            rv = t
        End If

    Case "fontface", "fontname", "typeface"  'from later 123 versions
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = rng.Cells(i, j).Font.Name
                Next j
            Next i
        Else
            rv = rng.Font.Name
        End If

    Case "fontsize", "pitch", "typesize"  'from later 123 versions
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = rng.Cells(i, j).Font.Size
                Next j
            Next i
        Else
            rv = rng.Font.Size
        End If

    Case "format"  'from CELL
    'Backwards compatibility w/123 - unnecessary
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = Evaluate( _
                      "=CELL(""Format""," & _
                      rng.Cells(i, j).Address(True, True, xlA1, True) & _
                      ")" _
                    )
                Next j
            Next i
        Else
            rv(i, j) = Evaluate( _
              "=CELL(""Format""," & _
              rng.Address(True, True, xlA1, True) & _
              ")" _
            )
        End If

    Case "formula"
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = rng.Cells(i, j).formula
                Next j
            Next i
        Else
            rv = rng.formula
        End If

    Case "formulaarray"  'questionable usefulness
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = rng.Cells(i, j).FormulaArray
                Next j
            Next i
        Else
            rv = rng.FormulaArray
        End If

    Case "formulahidden"
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = -(rng.Cells(i, j).FormulaHidden)
                Next j
            Next i
        Else
            rv = -(rng.FormulaHidden)
        End If

    Case "formulalocal"
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = rng.Cells(i, j).FormulaLocal
                Next j
            Next i
        Else
            rv = rng.FormulaLocal
        End If

    Case "formular1c1"
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = rng.Cells(i, j).FormulaR1C1
                Next j
            Next i
        Else
            rv = rng.FormulaR1C1
        End If

    Case "formular1c1local"
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = rng.Cells(i, j).FormulaR1C1Local
                Next j
            Next i
        Else
            rv = rng.FormulaR1C1Local
        End If

    Case "halign", "horizontalalignment"  'from later 123 versions
    'Note: different return values than 123. 0 = general alignment
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = _
                      rng.Cells(i, j).HorizontalAlignment - _
                      xlHAlignGeneral
                Next j
            Next i
        Else
            rv = rng.HorizontalAlignment - xlHAlignGeneral
        End If

    Case "hasarray"
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = -(rng.Cells(i, j).HasArray)
                Next j
            Next i
        Else
            rv = -(rng.HasArray)
        End If

    Case "hasformula"
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = -(rng.Cells(i, j).HasFormula)
                Next j
            Next i
        Else
            rv = -(rng.HasFormula)
        End If

    Case "hashyperlink", "hashyperlinks"
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = -(rng.Cells(i, j).Hyperlinks.Count > 0)
                Next j
            Next i
        Else
            rv = -(rng.Hyperlinks.Count > 0)
        End If

    Case "height", "rowheight"  'from later 123 versions - USEFUL!
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = rng.Cells(i, j).Height
                Next j
            Next i
        Else
            rv = rng.Height
        End If

    Case "hidden"  'see ColumnHidden and RowHidden - this is less useful
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = -(rng.Cells(i, j).Hidden)
                Next j
            Next i
        Else
            rv = -(rng.Hidden)
        End If

    Case "hyperlinkaddress"
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = rng.Cells(i, j).Hyperlinks(1).Address
                Next j
            Next i
        Else
            rv = rng.Hyperlinks(1).Address
        End If

    Case "indentlevel"
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = rng.Cells(i, j).rng.IndentLevel
                Next j
            Next i
        Else
            rv = rng.rng.IndentLevel
        End If

    Case "italic"  'from later 123 versions - USEFUL!
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = -(rng.Cells(i, j).Font.Italic)
                Next j
            Next i
        Else
            rv = -(rng.Font.Italic)
        End If

    Case "left"
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = rng.Cells(i, j).Left
                Next j
            Next i
        Else
            rv = rng.Left
        End If

    Case "leftborder"  'from later 123 versions
    'Note: many possible return values! wrap inside SIGN to test T/F
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = _
                      rng.Cells(i, j).Borders(xlEdgeLeft).LineStyle - _
                      xlLineStyleNone
                Next j
            Next i
        Else
            rv = rng.Borders(xlEdgeLeft).LineStyle - xlLineStyleNone
        End If

    Case "leftbordercolor"  'from later 123 versions
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = _
                      rng.Cells(i, j).Borders(xlEdgeLeft).ColorIndex
                Next j
            Next i
        Else
            rv = rng.Borders(xlEdgeLeft).ColorIndex
        End If

    Case "locked", "protect"  'from CELL
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = -(rng.Cells(i, j).Locked)
                Next j
            Next i
        Else
            rv = -(rng.Locked)
        End If

    Case "mergearea"  'NOTE: returns Range addresses!
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = rng.Cells(i, j).MergeArea.Address
                Next j
            Next i
        Else
            rv = rng.MergeArea.Address
        End If

    Case "mergecells"
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = -(rng.Cells(i, j).MergeCells)
                Next j
            Next i
        Else
            rv = -(rng.MergeCells)
        End If

    Case "name"
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = rng.Cells(i, j).Name
                Next j
            Next i
        Else
            rv = rng.Name
        End If

    Case "numberformat"
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = rng.Cells(i, j).NumberFormat
                Next j
            Next i
        Else
            rv = rng.NumberFormat
        End If

    Case "numberformatlocal"
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = rng.Cells(i, j).NumberFormatLocal
                Next j
            Next i
        Else
            rv = rng.NumberFormatLocal
        End If

    Case "orientation", "rotation"  'from later 123 versions
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = rng.Cells(i, j).Orientation
                Next j
            Next i
        Else
            rv = rng.Orientation
        End If

    Case "parentheses"  'from CELL
    'Backwards compatibility w/123 - unnecessary
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = Evaluate( _
                      "=CELL(""Parentheses""," & _
                      rng.Cells(i, j).Address(True, True, xlA1, True) & _
                      ")" _
                    )
                Next j
            Next i
        Else
            rv = Evaluate( _
              "=CELL(""Parentheses""," & _
              rng.Address(True, True, xlA1, True) & _
              ")" _
            )
        End If

    Case "pattern"  'from later 123 versions
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = _
                      rng.Cells(i, j).Interior.Pattern - _
                      xlPatternNone
                Next j
            Next i
        Else
            rv = rng.Interior.Pattern - xlPatternNone
        End If

    Case "patterncolor"  'from later 123 versions
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = _
                      rng.Cells(i, j).Interior.PatternColorIndex
                Next j
            Next i
        Else
            rv = rng.Interior.PatternColorIndex
        End If

    Case "prefix", "prefixcharacter"  'from CELL
    'Backwards compatibility w/123 - unnecessary
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = Evaluate( _
                      "=CELL(""Prefix""," & _
                      rng.Cells(i, j).Address(True, True, xlA1, True) & _
                      ")" _
                    )
                Next j
            Next i
        Else
            rv = Evaluate( _
              "=CELL(""Prefix""," & _
              rng.Address(True, True, xlA1, True) & _
              ")" _
            )
        End If

    Case "rightborder"  'from later 123 versions
    'Note: many possible return values! wrap inside SIGN to test T/F
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = _
                      rng.Cells(i, j).Borders(xlEdgeRight).LineStyle - _
                      xlLineStyleNone
                Next j
            Next i
        Else
            rv = rng.Borders(xlEdgeRight).LineStyle - xlLineStyleNone
        End If

    Case "rightbordercolor"  'from later 123 versions
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = _
                      rng.Cells(i, j).Borders(xlEdgeRight).ColorIndex
                Next j
            Next i
        Else
            rv = rng.Borders(xlEdgeRight).ColorIndex
        End If

    Case "row"  'from CELL - pointless - use ROW instead!
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = rng.Cells(i, j).Row
                Next j
            Next i
        Else
            rv = rng.Row
        End If

    Case "rowhidden"
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = -(rng.Cells(i, j).EntireRow.Hidden)
                Next j
            Next i
        Else
            rv = -(rng.EntireRow.Hidden)
        End If

    Case "scrollarea"
    'Who needs consistency?! Why doesn't this return a Range object?
        t = ws.ScrollArea  'invariant!

        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = t
                Next j
            Next i
        Else
            rv = t
        End If

    Case "sheet", "worksheet"  'from later 123 versions - USEFUL!
        t = ws.Index  'invariant!

        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = t
                Next j
            Next i
        Else
            rv = t
        End If

    Case "sheetname", "worksheetname"  'from later 123 versions - USEFUL!
        t = ws.Name  'invariant

        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = t
                Next j
            Next i
        Else
            rv = t
        End If

    Case "sheetcount", "sheetscount", "worksheetcount", "worksheetscount"
        t = wb.Worksheets.Count  'invariant

        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = t
                Next j
            Next i
        Else
            rv = t
        End If

    Case "shrinktofit"
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = -(rng.Cells(i, j).ShrinkToFit)
                Next j
            Next i
        Else
            rv = -(rng.ShrinkToFit)
        End If

    Case "stylename"
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = rng.Cells(i, j).Style.Name
                Next j
            Next i
        Else
            rv = rng.Style.Name
        End If

    Case "text"  'USEFUL!
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = rng.Cells(i, j).text
                Next j
            Next i
        Else
            rv = rng.text
        End If

    Case "textcolor"  'from later 123 versions - USEFUL!
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = rng.Cells(i, j).Font.ColorIndex
                Next j
            Next i
        Else
            rv = rng.Font.ColorIndex
        End If

    Case "top"
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = rng.Cells(i, j).Top
                Next j
            Next i
        Else
            rv = rng.Top
        End If

    Case "topborder"  'from later 123 versions
    'Note: many possible return values! wrap inside SIGN to test T/F
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = _
                      rng.Cells(i, j).Borders(xlEdgeTop).LineStyle - _
                      xlLineStyleNone
                Next j
            Next i
        Else
            rv = rng.Borders(xlEdgeTop).LineStyle - xlLineStyleNone
        End If

    Case "topbordercolor"  'from later 123 versions
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = _
                      rng.Cells(i, j).Borders(xlEdgeTop).ColorIndex
                Next j
            Next i
        Else
            rv = rng.Borders(xlEdgeTop).ColorIndex
        End If

    Case "underline"  'from later 123 versions - USEFUL!
    'Note: many possible return values! wrap inside SIGN to test T/F
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = _
                      rng.Cells(i, j).Font.Underline - _
                      xlUnderlineStyleNone
                Next j
            Next i
        Else
            rv = rng.Font.Underline - xlUnderlineStyleNone
        End If

    Case "usedrange"  'NOTE: returns Range addresses!
        t = ws.UsedRange.Address  'invariant
        
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = t
                Next j
            Next i
        Else
            rv = t
        End If

    Case "usestandardheight"
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = -(rng.Cells(i, j).UseStandardHeight)
                Next j
            Next i
        Else
            rv = -(rng.UseStandardHeight)
        End If

    Case "usestandardwidth"
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = -(rng.Cells(i, j).UseStandardWidth)
                Next j
            Next i
        Else
            rv = -(rng.UseStandardWidth)
        End If

    Case "valign", "verticalalignment"  'from later 123 versions
    'Note: different return values than 123. 0 = Bottom-aligned
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = _
                      rng.Cells(i, j).VerticalAlignment - _
                      xlVAlignBottom
                Next j
            Next i
        Else
            rv = rng.VerticalAlignment - xlVAlignBottom
        End If

    Case "visible", "sheetvisible", "worksheetvisible"
        t = -(ws.Visible)  'invariant

        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = t
                Next j
            Next i
        Else
            rv = t
        End If

    Case "width", "columnwidth"  'from CELL
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = rng.Cells(i, j).Width
                Next j
            Next i
        Else
            rv = rng.Width
        End If

    Case "workbookfullname"  'same as FileName in later 123 versions
        t = wb.FullName  'invariant

        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = t
                Next j
            Next i
        Else
            rv = t
        End If

    Case "workbookname"
        t = wb.Name  'invariant

        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = t
                Next j
            Next i
        Else
            rv = t
        End If

    Case "workbookpath"
        t = wb.path  'invariant

        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = t
                Next j
            Next i
        Else
            rv = t
        End If

    Case "wrap", "wraptext"  'from later 123 versions
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = -(rng.Cells(i, j).WrapText)
                Next j
            Next i
        Else
            rv = -(rng.WrapText)
        End If

    Case Else  'invalid property/characteristic
        t = CVErr(xlErrValue)  'invariant
        
        If rar Then
            For i = 1 To m
                For j = 1 To n
                    rv(i, j) = t
                Next j
            Next i
        Else
            rv = t
        End If

    End Select

    ExtCell = rv
End Function
 
Upvote 0
Wow...what a formula - do I copy that whole thing into my Macros? Sorry if I sound ignorant...never used complicated formulas like this before. Thank you for your help!!!
 
Upvote 0
suziq729 said:
Wow...what a formula - do I copy that whole thing into my Macros? Sorry if I sound ignorant...never used complicated formulas like this before. Thank you for your help!!!

To add ExtCell to your workbook:

Activate Tools|Macro|Visual Basic Editor;
Activate Insert|Module;
Copy the UDF above (the code for ExtCell) and paste it in the pane entitled "...(code)".
Activate File|Close and Return to Microsoft Excel.

Now the SumProduct formula will do the calculation you need.
 
Upvote 0
Ok...I think I am getting closer, but it is now returning "0" every time. Here is what I entered after copying the code into Editor:

=SUMPRODUCT(--(ExtCell("backgroundcolor",D9:D482,1)=B5),--(D9:D482="Y"))

Where B5 is filled with the desired color. I think that might be where I am going wrong?
 
Upvote 0
Sue, I just banged my head against the wall yesterday with this one. I read the exact same Help files, and I tried to copy from that, too. A friend in the office saved me from pulling my hair completely out by finding the answer.

You should be using COUNTIF instead of COUNT.

I am tallying survey results. One question happens to be a yes/no question, so I am counting Y's and N's, which sounds like what you are doing. Here is my formula in the cell:

=COUNTIF('Raw Data by MTF'!R4:R23,"Y")

...where Raw Data by MTF is the name of my worksheet and R4:R23 is the range of cells I am counting. I actually have two versions of this formula, one for "Y" and one for "N" in adjacent cells.

I now have to get these results into a chart. I am having a couple of specific problems, though. Are you any good with charts?

Thx,
Liam
 
Upvote 0

Forum statistics

Threads
1,223,918
Messages
6,175,365
Members
452,638
Latest member
Oluwabukunmi

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