In VBA Excel 2007, is there a substitution for VLookup?

  • Thread starter Thread starter RidgeView
  • Start date Start date
R

RidgeView

I did not realize that VLookup is not a viable function in Excel 2007 VBA.
Is there a substitute instruction? Currently I am doing a FOR/NEXT routine.
Thanks in Advance....
 
Use the following, substituting the range the formula is assigned to and the
arguments with the cell references you're using:

Range("A1").Formula = Application.WorksheetFunction.VLookup(Arg1, Arg2,
Arg3, [Arg4])
 
I am getting a null result...What am I doing wrong? I verified through
debugger that I am pulling a good name which is in the "O" column. The
information after "Vlookup" is all one line.

ActiveWorkbook.Sheets("Employee Periods 2-13").Select
EmpName = Cells(14, 1) ' This does grab the correct name

ActiveWorkbook.Sheets("Drop-Down Lists").Select
Range("A1").Formula = Application.WorksheetFunction.VLookup(EmpName,
"O5:P21", 2)
MsgBox Range("A1").Formula

Kevin B said:
Use the following, substituting the range the formula is assigned to and the
arguments with the cell references you're using:

Range("A1").Formula = Application.WorksheetFunction.VLookup(Arg1, Arg2,
Arg3, [Arg4])

--
Kevin Backmann


RidgeView said:
I did not realize that VLookup is not a viable function in Excel 2007 VBA.
Is there a substitute instruction? Currently I am doing a FOR/NEXT routine.
Thanks in Advance....
 
Dim EmpName as String
dim LookUpRng as range
dim res as variant

empname = worksheets("Employee Periods 2-13").Cells(14, 1).value

with worksheets("drop-down lists")
set lookuprng = .range("O5:p21")
end with

res = application.vlookup(empname, lookuprng,2, false)

if iserror(res) then
msgbox "Not found"
else
msgbox res
end if


I am getting a null result...What am I doing wrong? I verified through
debugger that I am pulling a good name which is in the "O" column. The
information after "Vlookup" is all one line.

ActiveWorkbook.Sheets("Employee Periods 2-13").Select
EmpName = Cells(14, 1) ' This does grab the correct name

ActiveWorkbook.Sheets("Drop-Down Lists").Select
Range("A1").Formula = Application.WorksheetFunction.VLookup(EmpName,
"O5:P21", 2)
MsgBox Range("A1").Formula

Kevin B said:
Use the following, substituting the range the formula is assigned to and the
arguments with the cell references you're using:

Range("A1").Formula = Application.WorksheetFunction.VLookup(Arg1, Arg2,
Arg3, [Arg4])

--
Kevin Backmann


RidgeView said:
I did not realize that VLookup is not a viable function in Excel 2007 VBA.
Is there a substitute instruction? Currently I am doing a FOR/NEXT routine.
Thanks in Advance....
 
Works Perfect !!!! Thanks alot...

Dave Peterson said:
Dim EmpName as String
dim LookUpRng as range
dim res as variant

empname = worksheets("Employee Periods 2-13").Cells(14, 1).value

with worksheets("drop-down lists")
set lookuprng = .range("O5:p21")
end with

res = application.vlookup(empname, lookuprng,2, false)

if iserror(res) then
msgbox "Not found"
else
msgbox res
end if


I am getting a null result...What am I doing wrong? I verified through
debugger that I am pulling a good name which is in the "O" column. The
information after "Vlookup" is all one line.

ActiveWorkbook.Sheets("Employee Periods 2-13").Select
EmpName = Cells(14, 1) ' This does grab the correct name

ActiveWorkbook.Sheets("Drop-Down Lists").Select
Range("A1").Formula = Application.WorksheetFunction.VLookup(EmpName,
"O5:P21", 2)
MsgBox Range("A1").Formula

Kevin B said:
Use the following, substituting the range the formula is assigned to and the
arguments with the cell references you're using:

Range("A1").Formula = Application.WorksheetFunction.VLookup(Arg1, Arg2,
Arg3, [Arg4])

--
Kevin Backmann


:

I did not realize that VLookup is not a viable function in Excel 2007 VBA.
Is there a substitute instruction? Currently I am doing a FOR/NEXT routine.
Thanks in Advance....
 

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

Back
Top