VB Lookup Syntax

  • Thread starter Thread starter Ken Hudson
  • Start date Start date
K

Ken Hudson

Hi,
Need help with the correct syntax for Vlookup in VB.

ActiveSheet.Name =
Application.WorksheetFunction.VLookup(D1,[ThisWorkbook.Name]ThisWorkbook.Sheets(2).Name!A1:D300,3,False)

isn't correct.
 
dim res as variant
dim LookUpRng as range
dim myVal as variant

set lookuprng = thisworkbook.sheets(2).range("a1:d300")

myval = activesheet.range("d1").value
res = application.vlookup(myval, lookuprng, 3, false)

if iserror(res) then
'what should happen
Res = "not found!"
end if

activesheet.name = res



Ken said:
Hi,
Need help with the correct syntax for Vlookup in VB.

ActiveSheet.Name =
Application.WorksheetFunction.VLookup(D1,[ThisWorkbook.Name]ThisWorkbook.Sheets(2).Name!A1:D300,3,False)

isn't correct.
 
Thanks Dave.

--
Ken Hudson


Dave Peterson said:
dim res as variant
dim LookUpRng as range
dim myVal as variant

set lookuprng = thisworkbook.sheets(2).range("a1:d300")

myval = activesheet.range("d1").value
res = application.vlookup(myval, lookuprng, 3, false)

if iserror(res) then
'what should happen
Res = "not found!"
end if

activesheet.name = res



Ken said:
Hi,
Need help with the correct syntax for Vlookup in VB.

ActiveSheet.Name =
Application.WorksheetFunction.VLookup(D1,[ThisWorkbook.Name]ThisWorkbook.Sheets(2).Name!A1:D300,3,False)

isn't correct.
 
Thanks Dave.
--
Ken Hudson


Dave Peterson said:
dim res as variant
dim LookUpRng as range
dim myVal as variant

set lookuprng = thisworkbook.sheets(2).range("a1:d300")

myval = activesheet.range("d1").value
res = application.vlookup(myval, lookuprng, 3, false)

if iserror(res) then
'what should happen
Res = "not found!"
end if

activesheet.name = res



Ken said:
Hi,
Need help with the correct syntax for Vlookup in VB.

ActiveSheet.Name =
Application.WorksheetFunction.VLookup(D1,[ThisWorkbook.Name]ThisWorkbook.Sheets(2).Name!A1:D300,3,False)

isn't correct.
 

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