ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Count numbers within a row (https://www.excelbanter.com/excel-programming/340786-count-numbers-within-row.html)

Noemi

Count numbers within a row
 
I have a row of numbers that can be repeated multiple times.

I would like to be able to count how many times the first number is listed
and continue all the way through until no more numbers a left to check.

eg
6
32
32
7
45
23
23
7
54

how do I write a program to go through each number and check how many times
that number is listed in the row.
The numbers always very so I cannot use a set value.

Thanks
Noemi

Gary Keramidas[_2_]

Count numbers within a row
 
this is a rudimentary solution, i'm sure someone can streamline it, but it
will put how many times a number is listed in the range, next to it in
column b

Option Explicit
Dim mg As Range
Dim LastRow As Long
Dim TestFor As Long
Dim cell As Range
Dim CurRow As Long
Sub test()
LastRow = Range("a1").End(xlDown).End(xlDown).Row
CurRow = LastRow
Set mg = Range("a1:a" & LastRow)

For Each cell In mg
TestFor = Range("a" & CurRow).Value
Range("b" & CurRow).Formula = "=CountIf(a1:a" & LastRow & "," & "" & TestFor
& "" & ")"
CurRow = CurRow - 1
Next cell

End Sub



--


Gary


"Noemi" wrote in message
...
I have a row of numbers that can be repeated multiple times.

I would like to be able to count how many times the first number is listed
and continue all the way through until no more numbers a left to check.

eg
6
32
32
7
45
23
23
7
54

how do I write a program to go through each number and check how many
times
that number is listed in the row.
The numbers always very so I cannot use a set value.

Thanks
Noemi




Bob Phillips[_6_]

Count numbers within a row
 
Why not just use a formula

=COUNTIF(A:A,A1)

and copy down

--
HTH

Bob Phillips

"Noemi" wrote in message
...
I have a row of numbers that can be repeated multiple times.

I would like to be able to count how many times the first number is listed
and continue all the way through until no more numbers a left to check.

eg
6
32
32
7
45
23
23
7
54

how do I write a program to go through each number and check how many

times
that number is listed in the row.
The numbers always very so I cannot use a set value.

Thanks
Noemi





All times are GMT +1. The time now is 05:28 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com