Input an ID number, find it among 65 ranges, obtain birth year

leosampieri

New Member
Joined
Jan 27, 2018
Messages
6
Hello everyone,
thanks in advance for your time.
I've got this problem:
1. I have a list of almost 24K ID numbers.
2. I have a table with ranges, saying: "from ID #1.000.000 to ID #2.000.000 was born in 1920"; and so with another 65 ranges, saying from this ID to that ID was born in this year. Look: https://snag.gy/lGVoQ1.jpg
3. So, I must check every ID I have with these conditions. Of course, I need to obtain the year that ID was born.

How can I get this done?
Thanks !
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Hi and welcome to the forum.

This will do what you want:

Code:
Sub KedForum2()
    Dim Srch As Long, lr As Long, rw As Long, Fnd As Long, Str1 As String, Str2 As String
    With Sheet1 'Change the sheet of the data here
        lr = .Cells(.Rows.Count, 7).End(xlUp).Row
        Srch = InputBox("Enter the ID you want to search for (leave out the period marks!)", "ID needed...")
        For rw = 2 To lr
            Str1 = .Cells(rw, 7)
            Str1 = (Left(Str1, 1) & Mid(Str1, 3, 3) & Right(Str1, 3))
            Str2 = .Cells(rw, 8)
            Str2 = (Left(Str2, 1) & Mid(Str2, 3, 3) & Right(Str2, 3))
            If Srch >= CLng(Str1) And Srch <= CLng(Str2) Then
                MsgBox "The year born is " & .Cells(rw, 9), , "Found year..."
                Exit Sub
            End If
        Next
    End With
    MsgBox "Sorry, year not found.", vbInformation, "Oh dear..."
End Sub

The code assumes you are using Sheet1 for your data, change it if this is not correct.

When you run it you will be prompted to enter the ID Number without the periods.

The sub then strips out the periods from the data and changes the string to a real number.

It then compares the number to the entered one to find the date.
 
Upvote 0
Are you looking for something like this:


Unknown
ABCDEF
1TableLookup ValueYear
21.000.0002.000.00019202.102.3211921
32.000.0012.500.0001921
42.500.0013.000.0001922
53.000.0013.500.0001923
63.500.0014.000.0001924
74.000.0014.500.0001925
84.500.0015.000.0001926
95.000.0015.500.0001927
105.500.0016.000.0001928
11
Sheet1
Cell Formulas
RangeFormula
F2=LOOKUP(E2,$A$2:$C$10)
 
Last edited:
Upvote 0
Hi and welcome to the forum.

This will do what you want:

Code:
Sub KedForum2()
    Dim Srch As Long, lr As Long, rw As Long, Fnd As Long, Str1 As String, Str2 As String
    With Sheet1 'Change the sheet of the data here
        lr = .Cells(.Rows.Count, 7).End(xlUp).Row
        Srch = InputBox("Enter the ID you want to search for (leave out the period marks!)", "ID needed...")
        For rw = 2 To lr
            Str1 = .Cells(rw, 7)
            Str1 = (Left(Str1, 1) & Mid(Str1, 3, 3) & Right(Str1, 3))
            Str2 = .Cells(rw, 8)
            Str2 = (Left(Str2, 1) & Mid(Str2, 3, 3) & Right(Str2, 3))
            If Srch >= CLng(Str1) And Srch <= CLng(Str2) Then
                MsgBox "The year born is " & .Cells(rw, 9), , "Found year..."
                Exit Sub
            End If
        Next
    End With
    MsgBox "Sorry, year not found.", vbInformation, "Oh dear..."
End Sub

The code assumes you are using Sheet1 for your data, change it if this is not correct.

When you run it you will be prompted to enter the ID Number without the periods.

The sub then strips out the periods from the data and changes the string to a real number.

It then compares the number to the entered one to find the date.

Paul!, thanks for your time. Really.
I'll try the code.
Let me as you a question: shall I be able to enter the 24K ID's all at once?
Thanks again,
 
Upvote 0
Are you looking for something like this:

Unknown
ABCDEF
1TableLookup ValueYear
21.000.0002.000.00019202.102.3211921
32.000.0012.500.0001921
42.500.0013.000.0001922
53.000.0013.500.0001923
63.500.0014.000.0001924
74.000.0014.500.0001925
84.500.0015.000.0001926
95.000.0015.500.0001927
105.500.0016.000.0001928
11

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet1

Worksheet Formulas
CellFormula
F2=LOOKUP(E2,$A$2:$C$10)

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>

Nishant, I'll try that out.
It's true that LOOKUP looks for the nearest value, too. I did not know that.
Regards, thanks a lot for your time.
 
Upvote 0
Cross posted https://www.excelforum.com/excel-fo...ind-it-among-65-ranges-obtain-birth-year.html

While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules). This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 
Upvote 0
Cross posted https://www.excelforum.com/excel-fo...ind-it-among-65-ranges-obtain-birth-year.html

While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules). This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.

Yes, you're right. I had not thought about that.
Sorry.
 
Upvote 0
Are you looking for something like this:

Unknown
ABCDEF
1TableLookup ValueYear
21.000.0002.000.00019202.102.3211921
32.000.0012.500.0001921
42.500.0013.000.0001922
53.000.0013.500.0001923
63.500.0014.000.0001924
74.000.0014.500.0001925
84.500.0015.000.0001926
95.000.0015.500.0001927
105.500.0016.000.0001928
11

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet1

Worksheet Formulas
CellFormula
F2=LOOKUP(E2,$A$2:$C$10)

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>

This worked, thanks !!
 
Upvote 0

Forum statistics

Threads
1,214,989
Messages
6,122,622
Members
449,093
Latest member
catterz66

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