View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Norman Jones[_2_] Norman Jones[_2_] is offline
external usenet poster
 
Posts: 421
Default How to insert VLOOKUP function in VBA?

Hi Dan,

Your question is unclear to me.

If you are asking for help with the
VBA syntax, try:

Res = Application.WorksheetFunction.VLookup(...)

or

Res = Application.VLookup(...)

If, however, you are asking if itis posssible
to use a Userform's TextBox values to
provide the function's argument values, I
see no problem. You could use something
like::

'=============
Option Explicit

Private Sub Command_Button()
Dim sStr As String
Dim sAddress As String
Dim Res As Variant
Dim Rng As Range
Const iCol As Long = 2

With Me
sStr = .TextBox1.Value
sAddress = .TextBox.Value
End With

Set Rng = ActiveSheet.Range(sAddress)

Res = Application.VLookup(sStr, Rng, iCol, False)
MsgBox Res

End Sub
'<<=============

If my suggestions are not helpful, you
might consider posting some addtional
explanatory detail.



---
Regards.
Norman


"Dan" wrote in message
...
I have a question:
Here is what I want to happen. I am using UserForm/TextBoxes in transfer
Argument 1 and Argument 2 in a Row 2 Sheet 2. And then I need to use in
VLOOKUP fucntion, as Argument 1 should be as a LOOKUP_VALUE and Argument 2
as
TABLE_ARRAY. Both or arguments should be dynamic, i.e. the actual data is
tracked in other sheet in the same workbook. Is there a way to make it
either
in Excel or VBA?
Dan.