Results 1 to 5 of 5

Search Multiple Tables, display found cell row data in userform

Threaded View

  1. #1
    Registered User
    Join Date
    02-14-2013
    Location
    York, England
    MS-Off Ver
    Excel 365
    Posts
    8

    Search Multiple Tables, display found cell row data in userform

    Apologies in advance if this is a long post, but I'll try and include as much detail as possible.

    Just in case it may make a difference to any of the code
    What I need help with is:
    • Coding the search function
    • Coding the next/previous function of the search (each has its own button)


    I have a Userform which will be used to capture incoming work opportunities. The work opportunities will be split over 5 worksheets, each with a corresponding table eg:
    • Worksheet (Tracker)/ Table_Main
    • Worksheet (Go)/ Table_Go
    • Worksheet(No Go)/ Table_NoGo

    Everything so far is working well. But I've hit a bit of a snag when building the search function.

    The user has the option of searching by Client or Opportunity name - Selected using a combobox, which in turn populates a second combobox with the available search names using the code below:
    Private Sub SearchBy_Change()
    Dim rngItems As Range
    Dim oDictionary As Object
    Dim tbl As ListObject
    Dim ws As Worksheet
    
    Select Case SearchBy.Text
        Case "Client"
        Me.SearchOptions.Clear
        SearchOptions.Value = "Please Select Client"
            For Each ws In ThisWorkbook.Worksheets
                For Each tbl In ws.ListObjects
                    Set rngItems = tbl.ListColumns("Client").DataBodyRange
                    Set oDictionary = CreateObject("Scripting.Dictionary")
                    
                        With Me.SearchOptions
                            For Each cel In rngItems
                                If oDictionary.exists(cel.Value) Then
                                'Do Nothing
                                Else
                                oDictionary.Add cel.Value, 0
                                .AddItem cel.Value
                                End If
                            Next cel
                        End With
                Next tbl
            Next ws
        Case "Opportunity Name"
        Me.SearchOptions.Clear
        SearchOptions.Value = "Please Select Opportunity Name"
            For Each ws In ThisWorkbook.Worksheets
                For Each tbl In ws.ListObjects
                    Set rngItems = tbl.ListColumns("Opportunity Name").DataBodyRange
                    Set oDictionary = CreateObject("Scripting.Dictionary")
                    
                        With Me.SearchOptions
                            For Each cel In rngItems
                                If oDictionary.exists(cel.Value) Then
                                'Do Nothing
                                Else
                                oDictionary.Add cel.Value, 0
                                .AddItem cel.Value
                                End If
                            Next cel
                        End With
                       
                Next tbl
            Next ws
    End Select
    This makes sure that no duplicate entries appear in the combobox.

    Once they've selected the Client or Opportunity name from the second combobox they then click the search button - which is where my issues begin.

    I need the search button to accomplish several different things, not necessarily in this order:
    1. search through a specific column in all the tables on all the sheets (depending on whether client or opportunity name has been previously selected)
    2. The code needs to identify on which sheet or in which table the matching entry was found
    3. Display several cell values from the found items row in several text boxes on the userform

    Number two is important because not all the tables have the columns in the same order (Which wasn't my idea but came from the powers that be.) For example, The Decision column in the main tracker is Column L, in the other four tables it's K. This affects which cells from the table row populate which textboxes on the Userform.

    I did start to build the code (in it's very early form - but couldn't progress as I didn't know how to accomplish 2 and therefore 3)

    Sub Search()
    Dim reference As String
    reference = UserForm1.SearchOptions.Value
    Dim aCell As Range
    Dim tbl As ListObject
    Dim ws As Worksheet
    
    
    
    'Select Case SearchBy.Value
        'Case "Opportunity Name"
            For Each ws In ThisWorkbook.Worksheets
            For Each tbl In ws.ListObjects
                Set aCell = tbl.ListColumns("Opportunity Name").DataBodyRange.Find(What:=reference, LookIn:=xlValues, _
                LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
                MatchCase:=False, SearchFormat:=False)
                
                If Not aCell Is Nothing Then
                UserForm1.TextBox12.Value = Offset(0, -7)
            Next tbl
            Next ws


    I have included a version of the tracker with any confidential info removed, which will hopefully shed some light on the above.

    Any help that anyone can give will be greatly appreciated, as I've been stuck on this for several days now.
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Userform to search and display data only
    By indub in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-21-2017, 12:24 PM
  2. Search and display data in userform
    By duesdextera in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-15-2016, 06:21 PM
  3. Replies: 1
    Last Post: 12-14-2015, 07:10 PM
  4. [SOLVED] Userform to search worksheet and display data back to the userform
    By zip247 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-05-2015, 05:46 AM
  5. Search Multiple Worksheets using a Userform and display in listbox.
    By nathandavies in forum Excel Programming / VBA / Macros
    Replies: 29
    Last Post: 11-18-2014, 10:22 AM
  6. Search worksheet for data in multiple textboxes in userform and display in another workshe
    By SierraKilo78 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-23-2013, 09:59 AM
  7. Search data from sheet & display in the userform
    By z-eighty2 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-25-2013, 01:08 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