Vlookup on middle 2 digits of a 4 digit number

rfinnegan

Board Regular
Joined
Mar 15, 2005
Messages
173
Office Version
  1. 365
Platform
  1. Windows
Hi All:

I'd like to perform a vlookup on the middle 2 digits of a 4 digit number. For example, I get a report that lists an employee number as 9341, when in fact the employee number is 34.

How can I have my vlookup only look at the 2 middle digits? Or another approach, ignore the first and last digit?

For what it's worth, the number the vlookup will look at almost always starts with a 9 (like the example above). And is, so far always a 4 digit number.

I'm using excel 2003 also.

Thanks in advance.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
if your 4 digit no is in A1 then

=INT(MOD(A1,1000)/10)

Just use that formula as the first argument of your vlookup
 
Upvote 0
Hi All:

I couldn't get either to work....then I realized they didn't work because I asked the wrong question.

What I have is the middle 2 numbers (the employee number) and I need to find it in a series of 4 digit numbers.

So using the example in the original post, my vlookup needs to find 34 when the number it is inbedded in is 9341.

Thanks again.

PS I tried to modify both the solutions that were submitted....I couldn't get it to work.
 
Upvote 0
Or..

=VLOOKUP(MID(A1,2,2),...


How about a combination of numbers and character, for example ( 311 Crew wages). I need the 311 to as my source reference for my vlookup. Instead of creating a different cell besides that title and only the 311 is indicated.

Thanks a lot.
 
Upvote 0
In the table where you are looking up the 9341, why not add a column to the left of 9341 and use the Mid function to just extract the 34

MID(A2,2,2)+0
 
Upvote 0
Hi All:

I couldn't get either to work....then I realized they didn't work because I asked the wrong question.

What I have is the middle 2 numbers (the employee number) and I need to find it in a series of 4 digit numbers.

So using the example in the original post, my vlookup needs to find 34 when the number it is inbedded in is 9341.

Thanks again.

PS I tried to modify both the solutions that were submitted....I couldn't get it to work.

Peter Moran's VLOOKUPNTH FUNCTION CAN ACHIEVE THIS

Code:
Function VLOOKUPNTH(lookup_value, table_array As Range, _
           col_index_num As Integer, nth_value)
' Extension to VLOOKUP function.  Allows for finding
' the "nth" item that matches the lookup value.
' 2/1/05 - Modified to handle Wildcards - "=" changed to "like"

Dim nRow As Long
Dim nVal As Integer
Dim bFound As Boolean
  VLOOKUPNTH = "Not Found"
  With table_array
    For nRow = 1 To .Rows.Count
      If .Cells(nRow, 1).Value Like lookup_value Then
      'If .Cells(nRow, 1).Value = lookup_value Then
        nVal = nVal + 1
      End If
      If nVal = nth_value Then
        VLOOKUPNTH = .Cells(nRow, col_index_num).Text
        Exit Function
      End If
    Next nRow
  End With
End Function

You'll need to use a wildcard "*"&A1&"*"
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,827
Members
452,946
Latest member
JoseDavid

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