Help Assigning a number to similar fields

kreativsoul

New Member
Joined
Jul 21, 2012
Messages
8
[h=2]I have a list of companies that looks something like this:[/h]

Company A
Company A
Company A
Company A
Company B
Company B
Company C

I would like to create a second column that assigns 1 to all instances of Company A, 2 to all instances of Company B and so on..
Is there a formula for something like this:

Comapany NameID No
Company A1
Company A1
Company A1
Company B2
Company B2
Company C3
Company C3

<tbody>
</tbody>



 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Hi and welcome to Mr Excel Forum,

If the companies are always grouped maybe this simpler formula
B2
=IF(COUNTIF($A$2:$A2,$A2)=1,MAX($B$1:$B1)+1,$B1)
copy down

Otherwise, this
B2
=IF(COUNTIF($A$2:$A2,$A2)=1,MAX($B$1:$B1)+1,INDEX($B$1:$B1,MATCH($A2,$A$1:$A1,0)))
copy down

M.
 
Upvote 0
If the companies are always grouped together as you show in your sample data, then consider using the simple formula below. Put this formula in B2 and copy it down to the end of your data...

=IF(A1=A2,B1,B1+1)
 
Upvote 0
Hi Rick,

There is a header in B1 so i think the formula needs a slight adjustment. Something like
=IF(A1=A2,B1,MAX(0,B1)+1)

M.
 
Upvote 0
Hi Rick,

There is a header in B1 so i think the formula needs a slight adjustment. Something like
=IF(A1=A2,B1,MAX(0,B1)+1)

I forgot about the header. If you wanted to use the same formula in all the cells, then I probably would do it this way...

=IF(A1=A2,B1,IF(ROW(A2)=2,1,B1+1))

However, simpler would be to just enter the number 1 in cell B2 and then put this in B3 and copy it down...

=IF(A2=A3,B2,B2+1)
 
Upvote 0

Forum statistics

Threads
1,213,565
Messages
6,114,338
Members
448,570
Latest member
rik81h

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