View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.misc
John John is offline
external usenet poster
 
Posts: 2,069
Default vlookup text in vba

Hi to all...
I am currently using Excel 2003. I am trying to use vlookup in VBA. First I
have a workbook with 8 spreadsheets. I have a Master Parts List spreadsheet
that updates 7 other worksheets within the workbook with the Vlookup in each
cell looking back at the Master Parts List spreadsheet. I would like to
accomplish this in VBA when I go to any one of the other spread sheets in
column A active cell value I type it looks up part number, description, and
unit of measure. I need the value in column A to remain text because I have
both numbers and alpha characters as part numbers. Here is what I have and I
keep getting #N/A.

Sub Lookup()
Dim lookuprng As Range
Dim myVal As String 'or whatever
Set lookuprng = Worksheets("Master Parts List").Range("$A$8:$D$5000")
myVal = ActiveCell.Value
ActiveCell.Offset(0, 1) = Application.VLookup(myVal, lookuprng, 2, False)
If myVal = "" Then
ActiveCell.Offset(0, 1) = ""
End If
End Sub

Thanks for any help I can get.