PDA

View Full Version : Solved: VBA code for number sequence excel



VBROB2B
06-15-2012, 10:59 PM
Please can someboby help me with a macro code in excel.

I have a column of various item names sorted alphabetically from top to bottom.
The item names are repeated under each other in various quantities ( eg some are only 1 , some are 2 , some are 3 etc ).
So reading the cells from top to bottom it may say orange then orange then apple then apple then apple then fig then fig then fig etc
I would love a code that would place in the cell opposite each item a number that reflects the number of times the item name is repeated.

eg for the first entry for "orange" it would have number "1" in cell opposite
For the second entry for "orange" it would have number "2" in cell opposite.
and for apples it would be 1 ,2 and 3 etc etc

I am a total novice in VBA but just love the way these macros work in excel.
Attached is file that shows what I am looking for

Thanks heaps to anyone of you who may be able to knock up a code for me

shrivallabha
06-15-2012, 11:04 PM
Welcome to VBAX.

While VBA can be used, a formula can also be employed and it will work just fine.

In cell B1 paste following formula and then copy down to the last row.
=COUNTIF($A$1:$A1,A1)

VBROB2B
06-16-2012, 01:40 AM
Thanks Shrivallabha
That works perfectly