VLookuP using VBA- Tweaking code slightly to work

Livin404

Well-known Member
Joined
Jan 7, 2019
Messages
743
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Good afternoon I'm currently use the code below and it does work perfectly; however, you can see I have a number "92" I constantly have to change since the quantity will never be the same. The second code you see is the approach I'm trying to take with this. There are no error codes, but nothing is happening either. The column with the three letter code I'm looking for is Column C on the sheet "72 Hr" the codes on found on the worksheet labeled "3 LTR" for which there are two columns A:B that has a name range of "IATA". I'm reasonably confident I'm nearly there, but need a little tug across the finish line on this one. Thank you so much,

VBA Code:
Private Sub VLOOK_UP()
For i = 1 To 92
Worksheets("72 Hr").Cells(i, 5).Value = Application.WorksheetFunction.VLookup(Worksheets("72 Hr").Cells(i, 3).Value, Worksheets("3 LTR").Range("A:B"), 2, 1)
Next
End Sub


VBA Code:
Private Sub VLOOK_UP()
Dim rng As Range
With Worksheets("72 Hr")
Set rng = .Range(.Range("C1"), .Cells(Rows.Count, 2).End(xlUp))
End With
With Worksheets("3 LTR")
.Range("A2").Offset(x, 0) = _
Application.WorksheetFunction.VLookup(.Range("A:B").Offset(x, 0), rng, 2, False)

End With
End Sub
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
So why not just edit the working code to be dynamic in finding the last row in your list?

VBA Code:
Private Sub VLOOK_UP()
    Dim I As Integer
    For I = 1 To Split(Worksheets("72 Hr").UsedRange.Address, "$")(4)
        Worksheets("72 Hr").Cells(I, 5).Value = _
        Application.WorksheetFunction.VLookup(Worksheets("72 Hr").Cells(I, 3).Value, _
        Worksheets("3 LTR").Range("A:B"), 2, 1)
    Next I
End Sub
 
Upvote 0
So why not just edit the working code to be dynamic in finding the last row in your list?

VBA Code:
Private Sub VLOOK_UP()
    Dim I As Integer
    For I = 1 To Split(Worksheets("72 Hr").UsedRange.Address, "$")(4)
        Worksheets("72 Hr").Cells(I, 5).Value = _
        Application.WorksheetFunction.VLookup(Worksheets("72 Hr").Cells(I, 3).Value, _
        Worksheets("3 LTR").Range("A:B"), 2, 1)
    Next I
End Sub
I did not think of it in those terms, I got hung up on what I've seen work for similar formulas. Having said that the formula you provide work flawless.
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,849
Members
449,051
Latest member
excelquestion515

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