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

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
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
1.000.0002.000.0002.102.321
2.000.0012.500.000
2.500.0013.000.000
3.000.0013.500.000
3.500.0014.000.000
4.000.0014.500.000
4.500.0015.000.000
5.000.0015.500.000
5.500.0016.000.000

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]1[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=00B0F0]#00B0F0[/URL] "]Table[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=00B0F0]#00B0F0[/URL] , align: right"][/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=00B0F0]#00B0F0[/URL] , align: right"][/TD]
[TD="align: right"][/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=00B0F0]#00B0F0[/URL] "]Lookup Value[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=00B0F0]#00B0F0[/URL] "]Year[/TD]

[TD="align: center"]2[/TD]

[TD="align: right"]1920[/TD]
[TD="align: right"][/TD]

[TD="align: right"]1921[/TD]

[TD="align: center"]3[/TD]

[TD="align: right"]1921[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]4[/TD]

[TD="align: right"]1922[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]5[/TD]

[TD="align: right"]1923[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]6[/TD]

[TD="align: right"]1924[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]7[/TD]

[TD="align: right"]1925[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]8[/TD]

[TD="align: right"]1926[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]9[/TD]

[TD="align: right"]1927[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]10[/TD]

[TD="align: right"]1928[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]11[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

</tbody>
Sheet1

[TABLE="width: 85%"]
<tbody>[TR]
[TD]Worksheet Formulas[TABLE="width: 100%"]
<thead>[TR="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]
[TH="width: 10px"]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
</thead><tbody>[TR]
[TH="width: 10px, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]F2[/TH]
[TD="align: left"]=LOOKUP(E2,$A$2:$C$10)[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]

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
1.000.0002.000.0002.102.321
2.000.0012.500.000
2.500.0013.000.000
3.000.0013.500.000
3.500.0014.000.000
4.000.0014.500.000
4.500.0015.000.000
5.000.0015.500.000
5.500.0016.000.000

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]1[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=00B0F0]#00B0F0[/URL] "]Table[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=00B0F0]#00B0F0[/URL] , align: right"][/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=00B0F0]#00B0F0[/URL] , align: right"][/TD]
[TD="align: right"][/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=00B0F0]#00B0F0[/URL] "]Lookup Value[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=00B0F0]#00B0F0[/URL] "]Year[/TD]

[TD="align: center"]2[/TD]

[TD="align: right"]1920[/TD]
[TD="align: right"][/TD]

[TD="align: right"]1921[/TD]

[TD="align: center"]3[/TD]

[TD="align: right"]1921[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]4[/TD]

[TD="align: right"]1922[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]5[/TD]

[TD="align: right"]1923[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]6[/TD]

[TD="align: right"]1924[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]7[/TD]

[TD="align: right"]1925[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]8[/TD]

[TD="align: right"]1926[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]9[/TD]

[TD="align: right"]1927[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]10[/TD]

[TD="align: right"]1928[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]11[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

</tbody>
Sheet1

[TABLE="width: 85%"]
<tbody>[TR]
[TD]Worksheet Formulas[TABLE="width: 100%"]
<thead>[TR="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]
[TH="width: 10px"]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
</thead><tbody>[TR]
[TH="width: 10px, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]F2[/TH]
[TD="align: left"]=LOOKUP(E2,$A$2:$C$10)
[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]

This worked, thanks !!
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,263
Members
452,627
Latest member
KitkatToby

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