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>



 

Some videos you may like

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Marcelo Branco

MrExcel MVP
Joined
Aug 23, 2010
Messages
16,411
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.
 

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
36,711
Office Version
  1. 2010
Platform
  1. Windows
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)
 

Marcelo Branco

MrExcel MVP
Joined
Aug 23, 2010
Messages
16,411
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.
 

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
36,711
Office Version
  1. 2010
Platform
  1. Windows

ADVERTISEMENT

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)
 

Watch MrExcel Video

Forum statistics

Threads
1,123,118
Messages
5,599,817
Members
414,341
Latest member
Mohammedsobhey

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
Top