Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Application.vlookup problem

Hello,

I'm having problem running the following piece of code and would
appreciate any help.

Firstly I've created two comboboxes, the result of one populates the
second. I then want to use the application.vlookup to populate textboxes
on my form.

Private Sub CB2_Change()

Dim appexcel as excel.application
Dim choice as string
Dim wks as worksheet
set choice = CB2.text 'this is the name of the sheet.
Set appexcel = Application

textbox1.text = application.vlookup(CB1.text,
wks(choice).range("A1:N200"),3,true) ' this line errors when I debug
and I think,it is to do with the choice variable.

etc

End sub

Hope this makes sense.

Regards

David
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Application.vlookup problem

David,

Since wks is defined as a Worksheet type object, you can't get
another sheet reference from it using (). Instead, you should
Set wks to the appropriate sheet and use that unadorned variable
in your VLOOKUP function:

Set wks = Worksheets(choice)
textbox1.text = application.vlookup(CB1.text, _
wks.range("A1:N200"),3,true)

Or, you Worksheets(choice) to specify the sheet:

textbox1.text = application.vlookup(CB1.text, _
Worksheets(choice).range("A1:N200"),3,true)


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"David Goodall" wrote in message
...
Hello,

I'm having problem running the following piece of code and
would appreciate any help.

Firstly I've created two comboboxes, the result of one
populates the second. I then want to use the
application.vlookup to populate textboxes on my form.

Private Sub CB2_Change()

Dim appexcel as excel.application
Dim choice as string
Dim wks as worksheet
set choice = CB2.text 'this is the name of the sheet.
Set appexcel = Application

textbox1.text = application.vlookup(CB1.text,
wks(choice).range("A1:N200"),3,true) ' this line errors when I
debug and I think,it is to do with the choice variable.

etc

End sub

Hope this makes sense.

Regards

David



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
application.worksheetfunction.vlookup JulieD Excel Programming 5 August 12th 04 04:42 PM
Application.OnKey problem R Avery Excel Programming 0 July 8th 04 06:38 PM
Problem with Application.Width Leo Excel Programming 2 February 2nd 04 09:22 PM
Application.OnKey problem Phillip Reeves[_2_] Excel Programming 1 January 23rd 04 06:46 PM
Application Problem Stuart[_10_] Excel Programming 7 November 16th 03 05:44 PM


All times are GMT +1. The time now is 06:03 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"