+ Reply to Thread
Results 1 to 7 of 7

specific search function with userform and dropdown list

  1. #1
    Registered User
    Join Date
    10-10-2022
    Location
    Germany
    MS-Off Ver
    365
    Posts
    31

    specific search function with userform and dropdown list

    Hello friends,

    I have created a userform with different dropdown menus. Everything works fine, but so far my code only displays the lines that contain the exact word that I select in the dropdown menu.

    My wish would be that also lines are selected, in which the word from the dropdown menu is plus something else.

    As an example:
    A table with column A in which in row 1: DE, in row 2: ENG, in row 3: PO and in row 4: DE PO.
    In my dropdown list I now have DE, ENG, PO. If I now select DE, only line 1 is displayed and not line 1 and line 4.


    How do I get this right?

    With Excel formulas this would be "*"&...&"*". Unfortunately, this does not work in VBA.

    My code is:

    Private Sub Suchen_DblClick(ByVal Cancel As MSForms.ReturnBoolean) 'L?ndersuche

    Dim S$, Rc As Range, Rb As Range, N&
    S = Dropdownland: If S = "" Then Exit Sub
    Set Rc = ActiveSheet.UsedRange.Rows
    Application.ScreenUpdating = False
    Rc.EntireRow.Hidden = False
    For Each Rc In Range("G62:G" & Rc(Rc.Count).Row)
    If StrComp(Rc.Columns(), S, 1) Then
    If Rc.Font.Bold Then Set Rb = Rc
    Rc.EntireRow.Hidden = True
    ElseIf Not Rb Is Nothing Then
    Rb.EntireRow.Hidden = False
    Set Rb = Nothing
    End If
    Next
    Application.ScreenUpdating = True
    Set Rb = Nothing

    Suchfeld = ""
    Unload Me
    End Sub

    I would be insanely happy about an answer!

    PS: can someone possibly tell me why the userform does not close on empty input? For that I have extra If S="" Then Exit Sub
    Attached Files Attached Files
    Last edited by emorej; 04-03-2023 at 06:32 AM.

  2. #2
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: specific search function with userform and dropdown list

    It would be much easier to help if we could see an example workbook. As we don't have one this is purely guesswork.

    Try swapping this line:
    Please Login or Register  to view this content.
    For this:
    Please Login or Register  to view this content.
    For the question about why the form isn't closing when you expect it to, we would need to see the example workbook to diagnose the issue.

    BSB

  3. #3
    Registered User
    Join Date
    10-10-2022
    Location
    Germany
    MS-Off Ver
    365
    Posts
    31

    Re: specific search function with userform and dropdown list

    Dear BSB,

    thank you for your answer. Unfortunately it did not work. I have now, as you suggested, attached a test file. Maybe it works with it. I would be very grateful if you could try again!

    Many thanks in advance
    LG

  4. #4
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: specific search function with userform and dropdown list

    Just to clarify, if the value selected in the userform combobox appears in the list then you want that row visible and if it doesn't appear in the list then you want it hidden?

    BSB

  5. #5
    Registered User
    Join Date
    10-10-2022
    Location
    Germany
    MS-Off Ver
    365
    Posts
    31

    Re: specific search function with userform and dropdown list

    yes exactly. But I want in addition, that when I search for a, also line 2 therefore a c is displayed to me. and not only line 4 and 5.

  6. #6
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: specific search function with userform and dropdown list

    Maybe this then?
    Please Login or Register  to view this content.
    BSB

  7. #7
    Registered User
    Join Date
    10-10-2022
    Location
    Germany
    MS-Off Ver
    365
    Posts
    31

    Re: specific search function with userform and dropdown list

    Quote Originally Posted by BadlySpelledBuoy View Post
    Maybe this then?
    Please Login or Register  to view this content.
    BSB
    thank you BSB
    indeed it works! but only if Rc.EntireRow.Hidden = True is in the next row. And I noticed that a large part of my code is completely unnecessary. Thanks a lot!

    Have a nice day

+ 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. Replies: 3
    Last Post: 08-30-2021, 01:17 PM
  2. Search Function with Dropdown List?
    By Rick-O-Shay in forum Excel General
    Replies: 2
    Last Post: 07-01-2020, 09:30 PM
  3. [SOLVED] Create an Excel Drop Down list with Search Suggestions ( Serachable Dropdown list )
    By PMH2384 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-11-2016, 12:03 AM
  4. Replies: 5
    Last Post: 04-23-2016, 11:34 AM
  5. Dropdown list search box using VBA
    By hanif in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-10-2014, 05:59 AM
  6. Replies: 4
    Last Post: 09-10-2013, 02:11 PM
  7. Replies: 9
    Last Post: 05-22-2011, 09:26 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