Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations SSS148 on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compile Error: Sub or Function not Defined 2

Status
Not open for further replies.

wzal

Mechanical
Mar 18, 2004
35
Hi,

I am new to VBA programming and trying to write some code in VB editor of excel to look up table,find value and display in the TextBox on the userform.

I wrote the following code.But when I run it,it send me
Compile Error:
Sub or function not defined with Vlookup highlighted.

Could anyone tell me why?

Code:
Private Sub CommandButton1_Click()
TextBox1 = VLookup(1, "A2:B8", 2)
End Sub

Thanks,
 
Replies continue below

Recommended for you

VLookup is an Excel Worksheet function, and not a VBA function. You might try including the various Excel objects into your application by including a reference to the Excel Object Library, and through the objects and methods from those objects may be able to build the vlookup function.
 
Hello,

Try using the MACRO RECORDER, inserting the VLOOKUP in a cell, then edit the code as necessary.



----------------------------------
Hope this helps.
----------------------------------

maybe only a drafter
but the best user at this company!
 
Use Worksheetfunction.vlookup, not just vlookup. After you type period after worksheetfunction the editor will show you the list of all available worksheet funcions you can use in VBA.
 
You'll need to reference the Excel object as well.

cExlObject.WorksheetFunction.VLookup
 
I'm having the exact same problem. I understand everything that has been written so far, but i have one question. What object has to be referenced? Actually i'm not even sure i know what the definition of an object is, because i am very new at this. Is it like the text box i need to refernce. I'm just not sure. If anyone could help that would be great.

Lesli
 
I would suggest that you start your own thread, and describe the situation you're in, and ask a specific question.
 
It's very simple!
All the Excel-functions are in VBA also, all what you have to use is:

e.g.
Application.WorksheetFunction._
VLookup(X, Range("Vlookup_Range"), 2, False)

.:JJ:.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor