Excel/Excel

Advertisement


Question
QUESTION: Sir,
I have a list of part numbers in Column A and I have hyper linked attached to those numbers in Column B which is a PDF specific to each part  number.
Now I am taking input in Cell C1 from a scanner which is giving me item number. Now as soon as input is received in the cell C1 macro gets triggered and displays a particular pdf. Everything is working great up til now.I have pasted the full code below.

But some parts we are procuring from different suppliers. In that case part number is same but what I want to display is different. Now I want to add in this code only a command that will look for part numbers as it is looking now. In case of single part number it goes as it is going now but in case of multiple part numbers it looks for Vendor code which will be written in column D for only those part numbers and asks for vendor code and then displays the relevant document. I hope I made myself clear.Please tell me if something is not clear
Please help. Thanks in advance.

Yours Sincerely
Saurabh Mundeja

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Not Intersect(Target, Range("C1")) Is Nothing Then macro
End Sub
Sub macro()
     Dim myR As Range
     Set myR = Worksheets("Sheet1").Range("A:A").Find( _
         What:=Worksheets("Sheet1").Range("C1").Value, LookIn:=xlFormulas)
       If Not myR Is Nothing Then
         ThisWorkbook.FollowHyperlink myR.Offset(, 1).Value
         
       Else
         MsgBox "Item Number Not Found. Please check The Number You have Entered"
         End If
End Sub

ANSWER: I am not sure what you mean by multiple part numbers; are there multiple part numbers in cell C1?

---------- FOLLOW-UP ----------

QUESTION: No sir, There are multiple entries of part numbers in master data because some parts are procured from one than more suppliers. In that case material part number is same but vendor code keeps on differing.
For eg if part number is abc..and it is procured from 2 vendors 123 and 789. than in cell c1 it will scan abc than it should look in column A and system will find 2 part numbers abc and abc. then he should ask for vendor code and  then display the relevant file.

Answer
Assuming the vendor name is in column C, you could do something like this:

Sub macro()
   Dim myR As Range
   Dim myPrevR As Range
   Dim sVendor As String
   Set myR = Me.Range("A:A").Find( _
         What:=Me.Range("C1").Value, LookIn:=xlFormulas)
   If Not myR Is Nothing Then
       If Application.WorksheetFunction.CountIf(Range("A1:A10"), Me.Range("C1")) > 1 Then
         sVendor = InputBox("Multiple partnumbers found, please enter the name of the vendor", "Multiple parts found", myR.Offset(, 1).Value)
         Set myPrevR = myR
         Do While myR.Offset(, 2).Value <> sVendor
         Set myR = Me.Range("A:A").FindNext(myR)
         If myR.Address = myPrevR.Address Then Exit Do
         Loop
       End If
       If sVendor = "" Or myR.Offset(, 2).Value = sVendor Then
         ThisWorkbook.FollowHyperlink myR.Offset(, 1).Value
       Else
         MsgBox "Item Number Not Found. Please check The Number You have Entered"
       End If
   Else
       MsgBox "Item Number Not Found. Please check The Number You have Entered"
   End If
End Sub  
About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here

Excel

All Answers


Answers by Expert:


Ask Experts

Volunteer


Jan Karel Pieterse

Expertise

Excel and Excel/VBA questions

Experience

Excel MVP

Organizations
Self employed Excel developer

Education/Credentials
Bachelor in Chemical Engineering

Awards and Honors
Microsoft MVP award since 2002

Past/Present Clients
Shell, Fortis bank, ABN-AMRO bank, Morgan Stanley, ...

©2016 About.com. All rights reserved.