Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Using Vlookup in VBA code

I am having some problems using the VLookup command within my VBA code. I
have successfully written some code which will pull the Novell User ID and
set it to strNovellUser.

I want to now use the strNovellUser in a VLookup function to lookup some
other information I have on another sheet (Users)in the workbook. I have
verified that my Novell UserID shows up in column 1 and there is data in
column 2, but the VLookup is either not finding it or it is not being set
properly to strName.

Below is part of the code I am using. Any help would be greatly appreciated.

===============
Public Sub BasicInfo()
Dim strName As String

strName = WorksheetFunction.VLookup(strNovellUser, _
Worksheets("Users").Range("A2:E14"), 2)
MsgBox "First Name is " & strName

End Sub
===============
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 212
Default Using Vlookup in VBA code

Hello Kathy,

Try with small modification as under (Added "FALSE")

strName = WorksheetFunction.VLookup(strNovellUser, _
Worksheets("Users").Range("A2:E14"), 2, FALSE)

If that too doesn't work try following (Further added "Trim")

strName = WorksheetFunction.VLookup(Trim(strNovellUser), _
Worksheets("Users").Range("A2:E14"), 2, FALSE)

Sharad

"Kathy - Lovullo" wrote in message
...
I am having some problems using the VLookup command within my VBA code. I
have successfully written some code which will pull the Novell User ID and
set it to strNovellUser.

I want to now use the strNovellUser in a VLookup function to lookup some
other information I have on another sheet (Users)in the workbook. I have
verified that my Novell UserID shows up in column 1 and there is data in
column 2, but the VLookup is either not finding it or it is not being set
properly to strName.

Below is part of the code I am using. Any help would be greatly
appreciated.

===============
Public Sub BasicInfo()
Dim strName As String

strName = WorksheetFunction.VLookup(strNovellUser, _
Worksheets("Users").Range("A2:E14"), 2)
MsgBox "First Name is " & strName

End Sub
===============



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Using Vlookup in VBA code

I would think you'd want your =vlookup() to have a 4th parm of false (exact
match required):

Public Sub BasicInfo()
Dim strName As Variant
strName = Application.VLookup(strNovellUser, _
Worksheets("Users").Range("A2:E14"), 2, 0)
if iserr(strname) then
msgbox "Not found"
else
MsgBox "First Name is " & strName
end if
End Sub

I like application.vlookup() so that I can check for an error. But that means I
have to declare strName as a variant (varName???).



Kathy - Lovullo wrote:

I am having some problems using the VLookup command within my VBA code. I
have successfully written some code which will pull the Novell User ID and
set it to strNovellUser.

I want to now use the strNovellUser in a VLookup function to lookup some
other information I have on another sheet (Users)in the workbook. I have
verified that my Novell UserID shows up in column 1 and there is data in
column 2, but the VLookup is either not finding it or it is not being set
properly to strName.

Below is part of the code I am using. Any help would be greatly appreciated.

===============
Public Sub BasicInfo()
Dim strName As String

strName = WorksheetFunction.VLookup(strNovellUser, _
Worksheets("Users").Range("A2:E14"), 2)
MsgBox "First Name is " & strName

End Sub
===============


--

Dave Peterson
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
vlookup VBA code cluckers Excel Discussion (Misc queries) 16 August 19th 09 08:40 PM
VLOOKUP as a vb code Tdp Excel Discussion (Misc queries) 5 November 25th 08 10:01 PM
Using VLOOKUP in VBA code Mark Excel Worksheet Functions 2 August 18th 06 04:41 PM
Vlookup in VB code alekm Excel Programming 1 September 7th 04 10:53 AM
Help with Vlookup code Gareth[_3_] Excel Programming 0 November 19th 03 07:28 PM


All times are GMT +1. The time now is 02:41 AM.

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"