error 1004 Unable to get the vlookup property

Nurul Ahda

New Member
Joined
Dec 15, 2022
Messages
1
Office Version
  1. 2016
Platform
  1. Windows
I wanna do an automated leave tracker. i want the staff name to appear based on their id using vlookup.
Can someone help where is the mistake?


Private Sub ComboBox1_Change()

If Me.ComboBox1.Value <> "" Then
Me.TextBox1.Value = Application.WorksheetFunction.VLookup(CLng(Me.ComboBox1.Value), ThisWorkbook.Sheets("Monthly Summary").Range("A:B"), 2, 0)
Else
Me.TextBox1.Value = ""

End If

End Sub
 

Attachments

  • Screenshot 2022-12-16 120435.png
    Screenshot 2022-12-16 120435.png
    20.9 KB · Views: 14
  • Screenshot 2022-12-16 120516.png
    Screenshot 2022-12-16 120516.png
    12.3 KB · Views: 16

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Hi and welcome to MrExcel!

If the data you put in the combobox does not exist, then the textbox remains empty.
How did you load the items into the combobox? Put here the code you used, also put examples, you must put more information so that you receive better help.

Use the find method:
VBA Code:
Private Sub ComboBox1_Change()
  Dim sh As Worksheet
  Dim f As Range
  
  Set sh = Sheets("Monthly Summary")
  
  TextBox1.Value = ""
  If ComboBox1.Value <> "" Then
    Set f = sh.Range("A:A").Find(ComboBox1.Value, , xlValues, xlWhole)
    If Not f Is Nothing Then
      TextBox1.Value = sh.Range("B" & f.Row).Value
    End If
  End If
End Sub

Review the following example:
 
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