Macro to count cells for x number

moorej

New Member
Joined
Mar 17, 2003
Messages
30
I'm not for sure if I could use a formula but would rather have a macro. Let's say I have a column with cell values of either an A, B, or C sorted asending. I would like to count the A's for "x" number and repeat until a change in A. Then count B's for "x" number and repeat, then C's. Something like this. The "x" for each will vary form time to time but I can change the "x" value within the macro.

Any input would be very helpful. Thank you.

A's in one column, numbers in another

A:1
A:2
A:3
A:1
A:2
A:3
A:1

Then B's

B:1
B:2
B:1
B:2
B:1
B:2
B:1

Then C's

C:1
C:2
C:3
C:4
C:5
C:1
C:2
C:3
C:4
C:5
C:1
C:2
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
A pivot table would give you what you want. Put the letters (A,B,C) in the row, put the numbers in the column, then put the numbers in the data as a count.

HTH
texasalynn
 
Upvote 0
I've never used a pivot table. Can I vary the numbers for each A,B, or C? Where my A's may be 1,2,..5, 1,2,..5 number sequence, and B's may be 1,2,...9, 1,2,...9, number sequence, and C's may be 1,2,...25, 1,2,...25.

Thanks
 
Upvote 0
Yes! Give the pivot table a shot as I suggested and see what results.

If you have questions, post back.

HTH
texasalynn
 
Upvote 0
Still not clear on a pivot table. How do I get the numbers in a column on the spreedsheet with the ABC's?
 
Upvote 0
Ok - here is a sample:
Book1
ABCD
1CharNumb
2A1
3A2
4A3
5A1
6A2
7A3
8A1
9B1
10B2
11B1
12B2
13B1
14B2
15B1
16C1
17C2
18C3
19C4
20C5
21C1
22C2
23C3
24C4
25C5
26C1
27C2
Sheet1


Then create the pivot table as I directed previously
Book1
ABCDEFG
3CountofNumbNumb
4Char12345GrandTotal
5A3227
6B437
7C3322212
8GrandTotal10842226
Sheet4


Does that help?
texasalynn
 
Upvote 0
The problem is I don't have any numbers beside the ABC's and would like to create them based on an "X" number. I really don't need to count how many A's have a 1 or 2 and so on. I just need a number in the column beside the letter.

Thanks
 
Upvote 0
I don't understand? Are the numbers you want next the letter dependant upon something? Do they mean something?

based on an "X" number
What does that mean?

texasalynn
 
Upvote 0
Let's say I have a column with 25 A's, 150 B's, and 500 C's. All in the same column. It is sorted in asending order. In the next column I want to be able to input a number count sequence for each group of ABC's. I may want the A's as 1,2,3,4,5,...1,2,3,4,5 or I may want them as 1,2..1,2..1,2 or maybe 1 through 25. Same for the B's and C's. I just need to get sequence numbers beside the letters in a sequence that I can select.

Thanks again for your help.
 
Upvote 0
Hi,

if you have your data in Col.A and start from the first row then

in cell B1
Code:
=COUNTIF(A$1:A1,A1) or =IF(COUNTIF(A$1:A2,A2)<=2,COUNTIF(A$1:A2,A2),IF(MOD(COUNTIF(A$1:A2,A2),2)=0,2,1)) or =IF(COUNTIF(A$1:A1,A1)<=5,COUNTIF(A$1:A1,A1),MOD(COUNTIF(A$1:A1,A1),5)) or =IF(COUNTIF(A$1:A1,A1)<=25,COUNTIF(A$1:A1,A1),MOD(COUNTIF(A$1:A1,A1),25))
w-click on the fill-handle, or copy it down

hope this helps

jindon
 
Upvote 0

Forum statistics

Threads
1,213,497
Messages
6,114,002
Members
448,543
Latest member
MartinLarkin

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