VBA VLOOKUP using a range for Column A

Livin404

Well-known Member
Joined
Jan 7, 2019
Messages
774
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hello, I've been finally on a roll with my project, but now I've run into a speedbump. The following is quite useful in my Vlookup. However, now the variable I need will fall with a range. I just need the variable match with what you see below the macro. Is there way I can do this without listing one very large range. In other words do I have to list each and every possibility in its own cell?"

VBA Code:
Sub Domestic_Ops()
      Dim i As Long, n As Variant, v As Variant
  If InStr(Range("H8"), "Domestic Ops") > 0 Then 'Only if Domestic Ops is in cell
    For i = 6 To Split(Worksheets("MSN Decoder").UsedRange.Address, "$")(4)

        n = Mid(Worksheets("MSN Decoder").Cells(i, "K").Value, 5, 5) ''' Extracts the 5-9 Character Position

          v = Application.VLookup(n, Worksheets("Domestic Ops").Range("A:B"), 2, 0)

        If IsError(v) Then v = Application.VLookup(Val(n), Worksheets("Domestic Ops").Range("A:B"), 2, 0)

        If Not IsError(v) Then Worksheets("MSN Decoder").Cells(i + 12, "H").Value = v
    Next i
End If
End Sub


In my 12 alpha numeric text the code will identify characters 5-9.
Below would be on Worksheet Domestic Ops

Column A I hope would be Column B
100AR - 299AR Agriculture

300CD - 499CD Commodities

500XX - 599EL Electronic
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
You need to clarify your question i don't understand.

What specifically do you see on Column A?
What do you want to see in column B?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
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