ADRIANA P
asked on
HOW TO COUNT EACH NUMBER
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
=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
ASKER
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
=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
ASKER
byundt yes you rigth
i need it in every 13 rows
but
i need it in every 13 rows
but
ASKER
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
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.
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
:)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
To run a macro:
1. If a nice person put a button on your worksheet, then click it
jajaj that's nice !!!
:)
working Great !!
1. If a nice person put a button on your worksheet, then click it
jajaj that's nice !!!
:)
working Great !!
ASKER
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
EACHNUMBER-COUNT_Q29019459.xlsm
ASKER
I need to count each number in this column
but for example 6 is more than 16 times
COUNTEACHNUMBER.xlsx
but for example 6 is more than 16 times
COUNTEACHNUMBER.xlsx
ASKER
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&"")-LE N(SUBSTITU TE(A:A&"", C1,"")))
EACHNUMBER-COUNT2_Q29019459.xlsm
=SUMPRODUCT(LEN(A:A&"")-LE
EACHNUMBER-COUNT2_Q29019459.xlsm
ASKER