generate code

apgmin

Board Regular
Joined
Mar 1, 2010
Messages
143
Office Version
  1. 2013
Platform
  1. Windows
In column A
I have the list of districts

Agar-Malwa
Alirajpur
Anuppur
Ashoknagar
Balaghat
Barwani
Betul
Bhind
Bhopal
Burhanpur
Chhatarpur
Chhindwara
Damoh
Datia
Dewas
Dhar
Dindori


In column B : I need a formula such that I can generate 2 unique characters to denote the districts

Similar to the 2 letters that denote the states in US like Alabama and Alaska both have the first 2 letters common but they are denoted by AL and AK

I need exactly something like this
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Similar to the 2 letters that denote the states in US like Alabama and Alaska both have the first 2 letters common but they are denoted by AL and AK

I need exactly something like this

There was no formula for the US states. People had to review them one by one and come to consensus over which two-letter abbreviation would be used. I suspect you man need to do that same.
 
Upvote 0
Yeah, and things could get a bit tricky, as you have to compare each one to all the other ones that have already been created.
And depending on how you do it, you could be using up other places two character abbreviation before you get there.

For example, let's say that you had some places whose first 3 letters are like this:
MAC...
MAI...
MIN...
MOP...

The first one would create "MA".
The second one cannot also use "MA". So if you look at the next letter, it would create "MI"
However, then when you get to the 3rd one, you cannot use "MI" because it is already used, even though its first two characters are different than everyone else's.

And what if you have a condition where all the letters are already used up?
Will you start to use letters NOT in the name, or maybe use numbers?

As you can see, there is a lot to consider, and no easy answers.
You would need to lay out the exact rules for us on how you want to create these codes, being sure to address the scenarios I mentioned above.
I am thinking that the solution will probably require VBA.
 
Upvote 0
I'm assuming that's not a complete list.
I can only go by the data you've supplied, but using
- first character
- second character
- last character
would identify the district in question.
 
Upvote 0
There was no formula for the US states. People had to review them one by one and come to consensus over which two-letter abbreviation would be used. I suspect you man need to do that same.
Thanks for your advice, now is the age of AI, so expecting some help
 
Upvote 0
Yeah, and things could get a bit tricky, as you have to compare each one to all the other ones that have already been created.
And depending on how you do it, you could be using up other places two character abbreviation before you get there.

For example, let's say that you had some places whose first 3 letters are like this:
MAC...
MAI...
MIN...
MOP...

The first one would create "MA".
The second one cannot also use "MA". So if you look at the next letter, it would create "MI"
However, then when you get to the 3rd one, you cannot use "MI" because it is already used, even though its first two characters are different than everyone else's.

And what if you have a condition where all the letters are already used up?
Will you start to use letters NOT in the name, or maybe use numbers?

As you can see, there is a lot to consider, and no easy answers.
You would need to lay out the exact rules for us on how you want to create these codes, being sure to address the scenarios I mentioned above.
I am thinking that the solution will probably require VBA.
The scenario you envisage will be remote, as there will be only say 10 names begining with a particular character so the combinations cannot get exhausted
 
Upvote 0
CENTER CODE.xlsx
FG
1MADHYA PRADESHCODE
2Agar-Malwa
3Alirajpur
4Anuppur
5Ashoknagar
6Balaghat
7Barwani
8Betul
9Bhind
10Bhopal
11Burhanpur
12Chhatarpur
13Chhindwara
14Damoh
15Datia
16Dewas
17Dhar
18Dindori
19Guna
20Gwalior
21Harda
22Indore
23Jabalpur
24Jhabua
25Katni
26Khandwa
27Khargone
28Maihar
29Mandla
30Mandsaur
31MAUGANJ
32Morena
33Narmadapuram
34Narsimhapur
35Neemuch
36Niwari
37Pandhurna
38Panna
39Raisen
40Rajgarh
41Ratlam
42Rewa
43Sagar
44Satna
45Sehore
46Seoni
47Shahdol
48Shajapur
49Sheopur
50Shivpuri
51Sidhi
52Singrauli
CENTER


G6 should come up with BA and G7 with BR as it is already taken earlier
 
Upvote 0
Thanks for your advice, now is the age of AI, so expecting some help
Then why are you not directing your request for help to an AI? There are only humans here.
 
Upvote 0
The scenario you envisage will be remote, as there will be only say 10 names begining with a particular character so the combinations cannot get exhausted
Can you describe the rule/logic you want to use?
In your list alone, you have 4 options that start with MA, and a a few that start with MAN.

Quite frankly, I do not think it is worth the effort trying to come up with some sort of automated VBA code to tried to do this for you, when there are so many variations.
I would simply take the two left-most characters, and then use a Conditional Formatting rule to highlight all the duplicates (ex. MA), and then change those manually.

If you truly want something more automated, and it doesn't really matter what the codes are, how about sorting your list alphabetically, and just take the first letter, then make the second go in order, i.e. MA, then MB, then MC, etc. As long as you don't have 26 different options starting with the same letter, that should work. If you do have more than 26 options starting with the same letter, then the code really aren't going to resemble the names at all, and you might as well just start with AA, AB, AC, etc.
 
Upvote 0

Forum statistics

Threads
1,215,268
Messages
6,123,966
Members
449,137
Latest member
yeti1016

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