Livin404
Well-known Member
- Joined
- Jan 7, 2019
- Messages
- 774
- Office Version
- 365
- 2019
- Platform
- 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?"
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
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