Assigning Numeric Identifiers

ajcormac

New Member
Joined
May 26, 2014
Messages
10
Hi there,

I have a column that contains non-numeric values (in some cases, repeated) - for example, software brands. Am I curious if there is a quick (1-step) way to assign numbers to each value in the column such that common elements will be assigned the same number. In other words, replace each value in a column with a numeric identifier.

Bonus if I can extend this to multiple columns.


Any thoughts on tackling this problem? My current method does not seem practical for performing this task multiple times.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Hi ajcomac, Are you wanting a formula or VBA approach?

For most purposes like this, one would create a table of unique values then use a lookup to assign the IDs. That can be done pretty quickly either manually or with VBA and provides you with a key to restore the non-numeric items if needed.

I don't think there's a formula-based way to replace the items with numeric IDs in 1-step. You could use a formula like this, then copy-paste special values to replace the items with numeric IDs.
Excel Workbook
AB
1IDItem
21apple
32banana
43cherry
54grape
65orange
76tangerine
87mango
92banana
103cherry
111apple
Sheet



To extend this to multiple columns, add a helper column that concatenates the fields into a key string....
Excel Workbook
ABCDE
1IDKey StringSourceSizeItem
21california|large|applecalifornialargeapple
32florida|small|bananafloridasmallbanana
43georgia|large|cherrygeorgialargecherry
54california|small|grapecaliforniasmallgrape
65florida|large|orangefloridalargeorange
76georgia|small|tangerinegeorgiasmalltangerine
87california|large|mangocalifornialargemango
92florida|small|bananafloridasmallbanana
103georgia|large|cherrygeorgialargecherry
118california|small|applecaliforniasmallapple
Sheet
 
Upvote 0
Hi Jerry,

Your solution is working excellently!
Thank you for the detailed response on how to tackle my problem - it is much appreciated.
 
Upvote 0
Hello Jerry,

I have a question. Why you use so many formulas if you can get the same result using just MATCH? I don't understand.

Thank you
 
Upvote 0
Hi simpleguy and welcome!

You are right that a simple match formula would be better for the dataset in my example.

The formula I suggested was intended to provide sequential numbers which a single match expression wouldn't do if there are items in column B that have their first instance after other item(s) in column B have had duplicates.

If we add a new item to the list, you'll see the numeric identifier skips the numbers 8-10...


Excel 2013
ABCD
1IDItemIDItem
21apple1apple
32banana2banana
43cherry3cherry
54grape4grape
65orange5orange
76tangerine6tangerine
87mango7mango
92banana2banana
103cherry3cherry
111apple1apple
128new item11new item
Sheet1
Cell Formulas
RangeFormula
A2=IF(COUNTIF(B$2:B2,B2)=1,MAX(A$1:A1)+1,INDEX(A$2:A2,MATCH(B2,B$2:B2,0)))
C2=MATCH(D2,D$2:D$100,0)

The OP didn't specify that the numeric identifiers needed to be consecutive, and yes, it would be much better to use a simple match formula if that wasn't a requirement.
 
Last edited:
Upvote 0
Thank you a lot Jerry, very good explanation.
I'm a beginner in Excel so this example was tricky to understood.
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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