Countif for horizontal arrays in a larger 2D array

des378

New Member
Joined
Jun 11, 2024
Messages
8
Office Version
  1. 365
Platform
  1. MacOS
Hi,

Need to count any numbers from a 2D array if it is standalone in a horizontal row - formula needs to work for whatever column its in

Ex:


COLUMN ACOLUMN BCOLUMN CCOLUMN D
25​
94​
83​
92​
78​
32​
56​
78​
21​
80​
31​
64​
21​
31​
91​

COLUMN A OUTPUT: 1 (only one number - 83 with no other numbers on that row)

COLUMN B OUTPUT: 1 (only one number - 56 with no other numbers on that row)

COLUMN C OUTPUT: 0 (all rows contain some number in it)

COLUMN D OUTPUT: 2 (two rows - 31 and 91 with no numbers in it)


Thanks!
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Here's one option, try:
Book1
ABCD
12594
283
3927832
456
57821
68031
76421
831
991
10
111102
Sheet6
Cell Formulas
RangeFormula
A11:D11A11=MAP(SEQUENCE(1,COLUMNS(A1:D9)),LAMBDA(m,SUM(--(BYROW(A1:D9,LAMBDA(r,(COUNTA(r)=1)*XMATCH(TRUE,r<>"")))=m))))
Dynamic array formulas.
 
Upvote 0
Solution
Another option:
Excel Formula:
=LET(x,SIGN(A1:D9),MMULT(SEQUENCE(1,ROWS(x),,0),x*(MMULT(x,SEQUENCE(COLUMNS(x),,,0))=1)))
 
Upvote 0
You've got good answers already, here's an UDF version though just for fun. Arguments are a mandatory range for your table, and an optional cell/1 column range to know which column to look at. If you don't set the optional range the function will look at the same column that it is used in.
VBA Code:
Function findIsolatedValues(table As Range, Optional optionalCol As Range)
On Error GoTo ErrorHandler
    If table.Columns.Count < 2 Then findIsolatedValues = "<Input table can't be single column>": Exit Function
    Dim colAsNr As Double

    If optionalCol Is Nothing Then
        colAsNr = Application.Caller.Column
    Else
        If optionalCol.Columns.Count > 1 Then findIsolatedValues = "<Input optionalCol must have 1 column>": Exit Function
        colAsNr = optionalCol.Column
    End If

    cLVC = 0
    For Each r In table.Rows
        If Cells(r.Row, colAsNr).Value <> "" Then
            rVC = 0
            For Each c In r.Columns
                If c.Value <> "" Then rVC = rVC + 1
            Next
            If rVC = 1 Then cLVC = cLVC + 1
        End If
    Next
    findIsolatedValues = cLVC
    Exit Function
ErrorHandler:
findIsolatedValues = "<Error>"
End Function
 

Attachments

  • EXCEL_7XBUA27PVO.gif
    EXCEL_7XBUA27PVO.gif
    102.5 KB · Views: 12
Upvote 0
@Cubist thanks for the solution - it works great for what I need. @Engberg love the VBA code as well but a little too complicated for what I'm trying to achieve - thanks anyways!
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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