+ Reply to Thread
Results 1 to 8 of 8

Vba code to find value across multiple worksheets and return adjacent data

  1. #1
    Registered User
    Join Date
    09-12-2012
    Location
    Northampton
    MS-Off Ver
    Excel 2007
    Posts
    32

    Vba code to find value across multiple worksheets and return adjacent data

    Hi

    I have looked all over and I cannot find an answer to what I originally thought would be quite straight forward
    I am trying to make a front page for my parts and prices workbook which allows a user to enter a part number and the vba code returns the information for that part number.

    The workbook consists of multiple worksheets (which is ongoing) one for each supplier and are named by supplier, so all unique, but all the layouts are the same.
    The part number begins in C11 and the rest of the required information is in D11-G11

    This is my borrowed code which will find and tell me which cell the entered part is in but I need it to return the rest of the information for that part number, vendor price cost etc

    Public Sub FindText()

    Dim ws As Worksheet, Found As Range
    Dim myText As String, FirstAddress As String
    Dim AddressStr As String, foundNum As Integer

    myText = InputBox("Enter text to find")

    If myText = "" Then Exit Sub

    For Each ws In ThisWorkbook.Worksheets
    With ws

    Set Found = .UsedRange.Find(what:=myText, LookIn:=xlValues, LookAt:=xlPart, MatchCase:=False)

    If Not Found Is Nothing Then
    FirstAddress = Found.Address

    Do
    foundNum = foundNum + 1
    AddressStr = AddressStr & .Name & " " & Found.Address & vbCrLf

    Set Found = .UsedRange.FindNext(Found)

    Loop While Not Found Is Nothing And Found.Address <> FirstAddress
    End If

    myNext:
    End With

    Next ws

    If Len(AddressStr) Then
    MsgBox "Found: """ & myText & """ " & foundNum & " times." & vbCr & _
    AddressStr, vbOKOnly, myText & " found in these cells"
    Else:

    MsgBox "Unable to find " & myText & " in this workbook.", vbExclamation
    End If
    End Sub

    Any help on this is greatly appreciated as I have no idea how macros work I just cannot get my head around it no matter how I try so I have massive respect for those of you that do
    Thanks

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,827

    Re: Vba code to find value across multiple worksheets and return adjacent data

    I think that it would be much easier to follow if we could see how your data is organized. Could you post a copy of your file? Include a detailed explanation of what you would like to do referring to specific cells and worksheets.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Registered User
    Join Date
    09-12-2012
    Location
    Northampton
    MS-Off Ver
    Excel 2007
    Posts
    32

    Re: Vba code to find value across multiple worksheets and return adjacent data

    Hi Thanks for the reply

    I have attached a sample workbook

    If you go to cell D3 on any supplier worksheet you can enter a part number and the rows down to D8 return the description and prices.
    What I am trying to do is use the worksheet named "Search" to have a message box in which a user can enter a part number and the rest of the information, description and prices appear with it.
    I have to have multiple worksheets as once I list all the suppliers and parts there will be more than the 65000 rows in total

    I am trying to avoid having to select each worksheet in turn and hope to eventually lock out all of the supplier worksheets so end users can only access the "Search" worksheet.
    Sorry should also mention if I can get the "Search" page working I will not need rows D8 - D11
    the worksheets are just for the data

    Hope my explanation is clear enough

    Thanks again
    Attached Files Attached Files

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,827

    Re: Vba code to find value across multiple worksheets and return adjacent data

    At present, the "Search" sheet is blank. I'm not sure how you want it to look. Do you want to enter a part number in let's say A2 and then search all the supplier sheets for that part number and return the appropriate data on the same row in the columns to the right starting in B1? Are all the part numbers unique values across all the supplier sheets or can there be duplicate part numbers?

  5. #5
    Registered User
    Join Date
    09-12-2012
    Location
    Northampton
    MS-Off Ver
    Excel 2007
    Posts
    32

    Re: Vba code to find value across multiple worksheets and return adjacent data

    I haven't made it look very pretty yet so feel free to use artistic licence but yes the Search sheet is blank, this is where end users will enter and retrieve data your suggestion of entering a number in A2 and returning the relevant data next to it is fine

    All part numbers are unique values it is unlikely but not impossible that different suppliers my use the same number one day if this could be factored in that would be useful but as I say it is unlikely we have been using these suppliers for some years and haven't had a duplicate yet

    Thanks again

  6. #6
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,827

    Re: Vba code to find value across multiple worksheets and return adjacent data

    Try the attached file. Just enter a part number in column A. Hopefully, this is what you were looking for.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    09-12-2012
    Location
    Northampton
    MS-Off Ver
    Excel 2007
    Posts
    32

    Re: Vba code to find value across multiple worksheets and return adjacent data

    That's exactly it thanks so much

  8. #8
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,827

    Re: Vba code to find value across multiple worksheets and return adjacent data

    My pleasure.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Need VBA to find matching data between worksheets & copy adjacent rows.
    By Helen62 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-16-2013, 12:19 AM
  2. Replies: 6
    Last Post: 03-06-2013, 03:30 PM
  3. Find, add and return values from multiple worksheets
    By Excelmad101 in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 02-27-2013, 04:53 PM
  4. How to find closest values in multiple columns and return adjacent values.
    By Patrician in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 01-28-2013, 01:47 PM
  5. Replies: 1
    Last Post: 08-08-2012, 08:40 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1