VBA Excel Vlookup

12Rev79

New Member
Joined
Mar 2, 2021
Messages
40
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Dear Expert,

I am not good in VBA but I tried the code below so far it works somehow
except the Vlookup Value that Meal 8 = 40.5 and Meal 3 =25.6
1. how can fix the code to have the correct value
2. how can I improve my Code if Quantity Oder increase should (Order Quantity x Amount)
Ex. Meal 6 Order Qty 2 Amount = 59.26

1618495181232.png


Sub myVLookUp()
'test vlookup
Range("M5").Select
Range(Selection, Selection).End(xlDown).Offset(0, 1).Select
Range(Selection, Selection).End(xlUp).Offset(1, 0).Value = "Meal 3"
Range(Selection, Selection).End(xlUp).Offset(0, 1).Value = 1
Range(Selection, Selection).End(xlUp).Offset(0, 2).Select

Dim lkvalue As Range
Dim tblArr As Range

Set lkvalue = Range("N6:N1000")
Set tblArr = Range("U6:V1000")

ActiveCell = Application.WorksheetFunction.VLookup(lkvalue, tblArr, 2, False)
Range(Selection, Selection).End(xlToLeft).Offset(0, 1).Select

End Sub


Thank you in advance your help,

12Rev79
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
One issue may be that your lookups are not in ascending order. Please sort all the 'Menu"/ Meal items...after Meal 1 comes Meal 10, which can throw off you Vlookup. I used the following code:
VBA Code:
Sub Vlkup()
    Dim c As Range
    For Each c In Range("m6:m15")
        If c <> "" Then
        c.Offset(0, 2) = WorksheetFunction.VLookup(c, Range("U7:V17"), 2, False)
        End If
    Next c
End Sub
you may need to modify your range? Please let me know if this has helped you.
 
Upvote 0
Solution

Forum statistics

Threads
1,214,812
Messages
6,121,702
Members
449,048
Latest member
81jamesacct

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