Vlookup on a VB Form

  • Thread starter Thread starter headly
  • Start date Start date
H

headly

I am trying to do a vlookup using the data from a form and a combobox but get
a 1004 error. Can someone explain why this generates an error on a form, but
works in the immediate window?

tbxTextBox.Value = Application.WorksheetFunction.VLookup(Int(Now() -
cbxComboBox.Value), Range("NamedDataRange"), 5, False)

Set to the onClick event of cbxComboBox, when someone picks a preset value
like 1 or 10, this triggers the vlookup to the named range and should return
the value to the text box tbxTextBox.
 
Here is code that does the same thing without using a worksheet function.

Set c = Range("NamedDataRange").Find( _
what:=Int(Now() - cbxComboBox.Value), _
LookIn:=xlValues)
If Not c Is Nothing Then
tbxTextBox.Value = c.Offset(0, 4)
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Vlookup Error 0
Vlookup Error 3
Vlookup result in a message box 10
Using vLookup function in VBA 4
VBA userform Vlookup Excel 1
vlookup, true false issue 8
VLookup using VB 5
Cant find VLookup property 5

Back
Top