How to fix this database?

kmprice710

Board Regular
Joined
Jan 8, 2014
Messages
87
Office Version
  1. 2019
Platform
  1. Windows
I am using MIcrosoft Office Professional Plus 2019

I have a spreadsheet on which every client has a unique numeric ID code. Then the client also has an alphanumeric ID code. Each numeric ID code is supposed to have only one alphanumeric ID code, but I found hundreds of mistaken alphanumeric ID codes.

I arranged the bad data on this sheet shown in the screenshot by sorting the numeric ID code. You can see the first numeric ID code, 1454952, has two alphanumeric ID codes associated, JB0058305 and JB0160111. I need each row of numeric ID codes to have only one alphanumeric ID code and the alphanumeric ID code must have the "lower" or "smaller" number.

In other words, 58305 is smaller than 160111 so the correct alphanumeric ID code is JB0058305. I need to put the correct alphanumeric ID code in column C.

How would I do this?
 

Attachments

  • Screenshot 2024-04-18 014954.jpg
    Screenshot 2024-04-18 014954.jpg
    122.2 KB · Views: 15

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Is there always only two characters at the beginning of the alphanumeric code?
 
Upvote 0
I'd probably tackle this in a couple of steps. You can omit step 1 if you're sure that column B is always sorted such that the 'incorrect' codes are at the end of each sequence, but I did it for certainty.

Step 1:
- Add a helper column that removes the first two characters from the alphanumeric ID using the formula =MID(B2,3,99) and copied down.
- Sort the data by numeric ID, ascending and Helper ascending. In your test data it didn't make a difference but just to be sure.
Step 2:
- In D3 add the formula =IF(A3=A2,B2,B3) and copy it down to the end.

See below.


Book1
ABCD
1numeric IDalphanumeric IDHelperfinal alpha ID
21454952JB00583050058305
31454952JB00583050058305JB0058305
41454952JB01601110160111JB0058305
51458134HK00437830043783HK0043783
61458134HK00437830043783HK0043783
71458134HK01582530158253HK0043783
81461842JW00571290057129JW0057129
91461842JW00571290057129JW0057129
101461842JW01599700159970JW0057129
Sheet1
Cell Formulas
RangeFormula
C2:C10C2=MID(B2,3,99)
D3:D10D3=IF(A3=A2,B2,B3)


Regards

Murray
 
Upvote 0
I'd probably tackle this in a couple of steps. You can omit step 1 if you're sure that column B is always sorted such that the 'incorrect' codes are at the end of each sequence, but I did it for certainty.

Step 1:
- Add a helper column that removes the first two characters from the alphanumeric ID using the formula =MID(B2,3,99) and copied down.
- Sort the data by numeric ID, ascending and Helper ascending. In your test data it didn't make a difference but just to be sure.
Step 2:
- In D3 add the formula =IF(A3=A2,B2,B3) and copy it down to the end.

See below.


Book1
ABCD
1numeric IDalphanumeric IDHelperfinal alpha ID
21454952JB00583050058305
31454952JB00583050058305JB0058305
41454952JB01601110160111JB0058305
51458134HK00437830043783HK0043783
61458134HK00437830043783HK0043783
71458134HK01582530158253HK0043783
81461842JW00571290057129JW0057129
91461842JW00571290057129JW0057129
101461842JW01599700159970JW0057129
Sheet1
Cell Formulas
RangeFormula
C2:C10C2=MID(B2,3,99)
D3:D10D3=IF(A3=A2,B2,B3)


Regards

Murray

Hi Murray,

Thanks for responding. That worked for the MOST part but not always. When I got down to situations in which there were four or more instances of the numeric ID code, then I had problems. See screenshot.

How can I avoid these errors?
 

Attachments

  • Screenshot 2024-04-19 194656.jpg
    Screenshot 2024-04-19 194656.jpg
    124.9 KB · Views: 11
Upvote 0
If you are happy to stick with sorting by Column A and then by the Helper column, the you can try this.
Put it in D2 and copy it down.
Excel Formula:
=IF(A2<>A1,B2,D1)
 
Upvote 0
Solution

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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