Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Vlookup on a VB Form

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Vlookup on a VB Form

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

"headly" wrote:

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.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
VLookup in a form [email protected] Excel Worksheet Functions 1 July 14th 08 12:23 AM
User Form Vlookup help? Carlos Excel Programming 3 April 5th 07 11:42 AM
Excel VB User Form Using Vlookup? [email protected] Excel Programming 2 January 13th 07 03:20 AM
Using Vlookup in chart form ashley k Excel Discussion (Misc queries) 1 September 12th 05 06:44 PM
list date in the form and vlookup sal21[_33_] Excel Programming 0 September 22nd 04 04:02 PM


All times are GMT +1. The time now is 10:11 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"