Link to home
Start Free TrialLog in
Avatar of ADRIANA P
ADRIANA PFlag for United States of America

asked on

HOW TO COUNT EACH NUMBER

NEED TO COUNT HOW MANY TIMES EACH NUMBERS REPEAT

THANKS !!
EACHNUMBER-COUNT.xlsx
Avatar of ADRIANA P
ADRIANA P
Flag of United States of America image

ASKER

RANGE FROM TO   1  2  3  4  5  6  7  8  9  0
Avatar of byundt
I assume that you want to count the number of times each digit appears in column A. If so, consider:
=COUNTIF(A:A,"*" & C1 & "*")+COUNTIF(A:A,C1 & C1)
In the above formula, cell C1 contains a digit (e.g. 0, 1, 2, 3, etc.).

The first COUNTIF counts the number of cells with at least one instance of the digit. The second COUNTIF counts the number of cells with two instances.

Note that this formula works if the numbers in column A are stored as text. You satisfied that criterion in your sample workbook, but perhaps not in the real workbook.

Also note that the formula does not handle 3 digit numbers correctly. You didn't have any in your sample data, so please advise if that situation is not valid in your real workbook.
EACHNUMBER-COUNT_Q29019459.xlsx
byundt

Thanks That's what i need !
but i have  one situation

i need count it every 13 rows
User generated image
all over the column
If I am understanding you correctly, you want to examine the counts in each group of 13 cells. If so, you could use:
=COUNTIF(A4:A15,"*" & C4 & "*")+COUNTIF(A4:A15,C4 & C4)

If I am not understanding your aim, please post your workbook with the desired answers, and I will devise formulas to suit.

Also advise if you need a macro to put the formulas and digits in the workbook.
EACHNUMBER-COUNT_Q29019459.xlsx
byundt yes  you rigth
i need it in every 13 rows
but
User generated image
Also advise if you need a macro to put the formulas and digits in the workbook.

yes because i need  every 13 rows
but how  sorry im not very computer expert
I'm glad you want a macro, because getting the formula to repeat properly is messy.

I goofed in my last formula. I needed to add some dollar signs to fix the reference to A4:A15 as the formula is copied down:
=COUNTIF(A$4:A$15,"*" & C4 & "*")+COUNTIF(A$4:A$15,C4 & C4)

Will be back with a macro shortly.
:)
ASKER CERTIFIED SOLUTION
Avatar of byundt
byundt
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
To run a macro:
1. If a nice person put a button on your worksheet, then click it
jajaj that's nice !!!

:)

working Great !!
Great ! Job !!
In a Private Message, ADRIANA P asked to have the results sorted. I added a sub to do that and reorganized the original sub to reflect a range variable rgResults for where the results should go.
Sub CountDigits()
Dim rg As Range, rgResults As Range
Dim i As Long, j As Long, n As Long
Dim frmla As String
Application.ScreenUpdating = False
Set rg = Range("A4")    'First cell with numbers
Set rg = Range(rg, Cells(Rows.Count, rg.Column).End(xlUp))  'All the numbers in that column

n = rg.Rows.Count
For i = 1 To n Step 13     'Assume groups of 12 numbers, with a blank row in between
    j = rg.Row + i - 1
    Set rgResults = rg.Cells(i, 3).Resize(10, 2)
    rgResults.Columns(1).Value = Application.Transpose(Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9))
    frmla = "COUNTIF(R" & j & "C[-3]:R" & (j + 11) & "C[-3],"
    frmla = "=" & frmla & """*"" & RC[-1] & ""*"") + " & frmla & "RC[-1] & RC[-1])"
    rgResults.Columns(2).FormulaR1C1 = frmla
    SortByCount rgResults
Next
End Sub

Sub SortByCount(rgResults As Range)
With rgResults.Worksheet.Sort
    .SortFields.Clear
    
        'Use Order:=xlAscending if you want to sort with smallest values first
    .SortFields.Add Key:=rgResults.Columns(2), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
    .SetRange rgResults
    .Header = xlNo
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply
End With
End Sub

Open in new window

EACHNUMBER-COUNT_Q29019459.xlsm
I need to count each number in this column
but for example  6 is more than 16 times
COUNTEACHNUMBER.xlsx
9 is more than 11
Cells A54:A118 contain numbers, not text. Notice how they don't have little green warning triangles at top left of each cell. The digits in those numbers are not counted by COUNTIF formula in column D. Use the SUMPRODUCT formula shown below instead.

=SUMPRODUCT(LEN(A:A&"")-LEN(SUBSTITUTE(A:A&"",C1,"")))
EACHNUMBER-COUNT2_Q29019459.xlsm