+ Reply to Thread
Results 1 to 22 of 22

Search multiple worksheets for multiple data and display in userform

  1. #1
    Registered User
    Join Date
    06-06-2025
    Location
    Tulsa
    MS-Off Ver
    MS Office Professional Plus 2013
    Posts
    23

    Search multiple worksheets for multiple data and display in userform

    I have a music collection workbook and a userform that I can search for recordings. I'm trying to add another search to pull up a track with it's associated recording and artist. The tracks are on their own worksheet and the recordings are on another worksheet. I have attached the current file and I need code to find a particular song, its artist, title of recording and track number on that recording to display in a listbox called "lstSearchTrks". And instead of a command button to apply the search, I would like the search to show responses as I type. Is this possible? I can use all the help I can get.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    31,297

    Re: Search multiple worksheets for multiple data and display in userform

    You have the basic coding in the SEARCH Userform where selecting RECORDING gives the required data so why cannot this be used/modified to find Songs?

    I can see no reason for not "combining" the 2 searches.

    And do you need sheets RECORDING/TRACKS/RECORDING -TRACKS rather just than the latter as your "database"?
    Last edited by JohnTopley; 07-02-2025 at 02:12 PM.
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  3. #3
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,659

    Re: Search multiple worksheets for multiple data and display in userform

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  4. #4
    Registered User
    Join Date
    06-06-2025
    Location
    Tulsa
    MS-Off Ver
    MS Office Professional Plus 2013
    Posts
    23

    Re: Search multiple worksheets for multiple data and display in userform

    Thank you so much for your comments. I was trying to come up with a way to do this search and thought putting both recordings and tracks on the same sheet would do the trick. It didn't. I also tried to modify the "Select Criteria To Search For" drop down to include Song titles, as you suggest, but failed there also. I just didn't want to display all the other column info like, "Recording ID", "Format", "Genre", and "Notes" when searching for a Song. That's why I asked for help. If you know how I can code the one search to include Song titles which will bring up the Song Title, Track no, Artist, and Name of recording, I'm all for doing that.

  5. #5
    Registered User
    Join Date
    06-06-2025
    Location
    Tulsa
    MS-Off Ver
    MS Office Professional Plus 2013
    Posts
    23

    Re: Search multiple worksheets for multiple data and display in userform

    BRILLIANT! It works perfectly. I'll play with it a little while just to make sure there are no quirks I need to ask you about, and then I will post "solved". Thank you so much.

  6. #6
    Registered User
    Join Date
    06-06-2025
    Location
    Tulsa
    MS-Off Ver
    MS Office Professional Plus 2013
    Posts
    23

    Re: Search multiple worksheets for multiple data and display in userform

    AlphaFrog, I discovered something that will require a little different coding, but I don’t know how. I see that you used the
    sheet(Recordings-Tracks) to pull the data from, which works great until you get to a point where the Recordings side has blank cells.
    This results in the Artist and Recording columns being blank (see attached screen shot). Is there a way to code this using
    Sheet2 and Sheet4 in combination instead of Sheet6? Or maybe something else?
    Attached Images Attached Images

  7. #7
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    31,297

    Re: Search multiple worksheets for multiple data and display in userform

    One "issue": the search is not a predictive one but simply all songs containing "p" in the title (in the example).

    And illustates the need for a single "database"! Or better "links" between multiple "databases".
    Last edited by JohnTopley; 07-03-2025 at 01:27 AM.

  8. #8
    Registered User
    Join Date
    06-06-2025
    Location
    Tulsa
    MS-Off Ver
    MS Office Professional Plus 2013
    Posts
    23

    Re: Search multiple worksheets for multiple data and display in userform

    JohnTopley, I believe you are absolutely correct. Do you know how this could be coded to get the results I need? Thanks.

  9. #9
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    31,297

    Re: Search multiple worksheets for multiple data and display in userform

    As I stated before, you have the basis of the required code ..

    Please Login or Register  to view this content.
    txtArtistSearch is replaced by txtSongSearch

    lstSearch by lstSearchTrks

    etc

    ... is the code not yours?

    You stiil (IMHO) need to resolve how to best organise your data.

  10. #10
    Registered User
    Join Date
    06-06-2025
    Location
    Tulsa
    MS-Off Ver
    MS Office Professional Plus 2013
    Posts
    23

    Re: Search multiple worksheets for multiple data and display in userform

    Thanks for the info. The code I currently have was given to me through Excelforum. My knowledge of Excel VBA is very limited. It seems if I use the same code with "txtSongSearch" it won't limit the results to just Trk No, Song Title, Artist and Recording. I don't want the columns of Format, Genre, Released, and Notes to be in my result. Also, the same code will only search the Recordings Sheet and not the Tracks sheet.

  11. #11
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,659

    Re: Search multiple worksheets for multiple data and display in userform

    Quote Originally Posted by P.alexander View Post
    AlphaFrog, I discovered something that will require a little different coding, but I don’t know how. I see that you used the
    sheet(Recordings-Tracks) to pull the data from, which works great until you get to a point where the Recordings side has blank cells.
    This results in the Artist and Recording columns being blank (see attached screen shot). Is there a way to code this using
    Sheet2 and Sheet4 in combination instead of Sheet6? Or maybe something else?
    It would require more than a little different coding. Finding matching tracks on the Tracks sheet and then doing another lookup to find the recording of that track on on the Recordings sheet is technically do-able, but a bit of a PITA. Are you asking to search for the matching Rec. ID on the Recordings sheet for each matched Track?

    JohnTopley, I believe you are absolutely correct. Do you know how this could be coded to get the results I need? Thanks.
    I'm confused. You agree with Topley about consolidating the data onto one sheet. Then ask again how to do this without consolidating the data. What's the issue with consolidating to one sheet? It seems that a cleanup of the Recordings-Tracks sheet would get you what you want. What am I missing?
    Last edited by AlphaFrog; 07-03-2025 at 10:34 AM.

  12. #12
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,659

    Re: Search multiple worksheets for multiple data and display in userform

    Quote Originally Posted by P.alexander View Post
    Thanks for the info. The code I currently have was given to me through Excelforum. My knowledge of Excel VBA is very limited. It seems if I use the same code with "txtSongSearch" it won't limit the results to just Trk No, Song Title, Artist and Recording. I don't want the columns of Format, Genre, Released, and Notes to be in my result. Also, the same code will only search the Recordings Sheet and not the Tracks sheet.
    I didn't follow that at all. Sorry.

  13. #13
    Registered User
    Join Date
    06-06-2025
    Location
    Tulsa
    MS-Off Ver
    MS Office Professional Plus 2013
    Posts
    23

    Re: Search multiple worksheets for multiple data and display in userform

    AlphaFrog, I am so sorry for the confusion. It is totally acceptable to me to use the "Recordings-Tracks" sheet if the results will give me what I want. The code you sent me before was so very close, except for the missing Artist and Recording columns data. What can I do to make up for this? Thanks again for all your help with this.

  14. #14
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    31,297

    Re: Search multiple worksheets for multiple data and display in userform

    Please Login or Register  to view this content.
    Still need to correct the "Recording" ("dummy" in attached): CORRECTED
    Attached Files Attached Files
    Last edited by JohnTopley; 07-03-2025 at 11:03 AM. Reason: Updated macro

  15. #15
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,659

    Re: Search multiple worksheets for multiple data and display in userform

    Quote Originally Posted by P.alexander View Post
    AlphaFrog, I am so sorry for the confusion. It is totally acceptable to me to use the "Recordings-Tracks" sheet if the results will give me what I want. The code you sent me before was so very close, except for the missing Artist and Recording columns data. What can I do to make up for this? Thanks again for all your help with this.
    This issue is not the code, but the missing Artist and Recording information listed on the Recordings-Tracks sheet. If you fill-in the missing info on the sheet, your problem is solved.

  16. #16
    Registered User
    Join Date
    06-06-2025
    Location
    Tulsa
    MS-Off Ver
    MS Office Professional Plus 2013
    Posts
    23

    Re: Search multiple worksheets for multiple data and display in userform

    Actually, there is no missing information. Each recording has 10 to 15 tracks, so the recording side will never be as long as the track side.

  17. #17
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    31,297

    Re: Search multiple worksheets for multiple data and display in userform

    Did you try (updated) code from post #14?

    And take a look here on how to organise data .....

    https://www.youtube.com/watch?v=rcrsqyFtJ_4

    As an example, a CD has many songs but the same song can appear on many CDs [one-to-many relationship].

    Similary, an artist can appear on many CDs and a song can be "covered" by many artists [one-to-many relationships].

    I do not know the volume of data you have (or plan to ) but I would give some thought how best to organise your "database".

    My previous suggestion of combining 2 of sheets was to avoid data redundancy, as the same data is in both sheets, BUT it will be better to "normalise" the data.
    Last edited by JohnTopley; 07-04-2025 at 05:49 AM.

  18. #18
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,659

    Re: Search multiple worksheets for multiple data and display in userform

    On the TRACKS sheet, put this formula in G2
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    And this in H2
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Copy these two formulas down the length of the data table

    Use this code
    Please Login or Register  to view this content.

  19. #19
    Registered User
    Join Date
    06-06-2025
    Location
    Tulsa
    MS-Off Ver
    MS Office Professional Plus 2013
    Posts
    23

    Re: Search multiple worksheets for multiple data and display in userform

    AlphaFrog, thank you so much for the coding. There is just one more issue that I think can be easily fixed, but I'm not sure. When I enter a
    new recording the track Sheet is not updating columns G and H. You can see from the screen shot attached that the end of the list has left off
    the Recording and Artist. Thanks Again. PAlexander
    Attached Images Attached Images

  20. #20
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    31,297

    Re: Search multiple worksheets for multiple data and display in userform

    With the current formula, you would get an "N/A#" if "REC ID" 49 did not exist in "Tracks" so this suggests there no formula in rows 583 down

    Change formula to

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Formula: copy to clipboard
    Please Login or Register  to view this content.


    For future reference: please post a file not a picture, which is of no value when trying to identify/correct problems.
    Last edited by JohnTopley; 07-05-2025 at 06:08 AM.

  21. #21
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,659

    Re: Search multiple worksheets for multiple data and display in userform

    In the frmNewTracks code module, add the two .Formula lines from below to the Sub WriteDataToSheet.


    Private Sub WriteDataToSheet()
    Dim newRow As Long
    With Sheet4
    newRow = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
    .Cells(newRow, 1).Value = txtTrackID.Value
    .Cells(newRow, 2).Value = txtTrackNo.Value
    .Cells(newRow, 3).Value = txtTrackTitle.Value
    .Cells(newRow, 4).Value = txtComposer1.Value
    '.Cells(newRow, 5).Value = txtComposer2.Value
    '.Cells(newRow, 6).Value = txtComposer3.Value
    .Cells(newRow, 5).Value = txtLength.Value
    .Cells(newRow, 6).Value = txtRecordingID.Value
    .Cells(newRow, 7).Formula = "=VLOOKUP(F" & newRow & ",Recordings!A:B,2,0)"
    .Cells(newRow, 8).Formula = "=VLOOKUP(F" & newRow & ",Recordings!A:C,3,0)"

    End With
    'frmRecordings.lstRecordings_Click
    End Sub

  22. #22
    Registered User
    Join Date
    06-06-2025
    Location
    Tulsa
    MS-Off Ver
    MS Office Professional Plus 2013
    Posts
    23

    Re: Search multiple worksheets for multiple data and display in userform

    Beautiful. I would never have come up with this code. Thank You.

+ 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. [SOLVED] Search Multiple Tables, display found cell row data in userform
    By Icesurf3r in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-24-2019, 06:14 AM
  2. Search data from multiple worksheets and display in a Form
    By bash in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-08-2019, 07:38 AM
  3. Search and edit the data from multiple worksheets from userform
    By bujaber10 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-06-2019, 10:01 AM
  4. 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
  5. 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
  6. VBA: Userform search from multiple worksheets
    By jyl_woo in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-29-2011, 09:38 AM

Tags for this Thread

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