+ Reply to Thread
Results 1 to 9 of 9

String Selection Popup

  1. #1
    Registered User
    Join Date
    11-17-2011
    Location
    Ottawa
    MS-Off Ver
    Excel 2003
    Posts
    18

    String Selection Popup

    Hello All,

    In Excel VBA, I am trying to create a single macro that will

    A) search for a string (let's say "Bay") within an entire worksheet

    B) return all results of the search containing the string in a list ("Bay st", "Bay Av", "Bayview", etc.)

    C) allow the user to select one entry from the list (the list would be in numbered form, perhaps in a popup, showing 1. Bay st 2. Bay Av 3. Bayview, etc

    D) after the user selects an entry (let's say the user clicks Bayview), the entire row which contains the selection (Bayview) is selected

    *Thanks for any solutions or advice and please not that are not an option for what I'm doing*

    Much appreciated,

    Nick
    Last edited by touchofknowledge; 11-21-2011 at 11:57 AM.

  2. #2
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: String Selection Popup

    Attached is an example showing how you should go about setting something like this up.
    Attached Files Attached Files
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  3. #3
    Registered User
    Join Date
    11-17-2011
    Location
    Ottawa
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: String Selection Popup

    Hi Dave. That is brilliant - thanks for the reply! However, I extracted the form (without changing the name), and imported it into the file I'm working on. Then when I tried this simple macro (which worked on your example file):
    Sub RunForm()
    UserForm1.Show
    End Sub

    I got a subscript out of range (Run Time Error 9) error.

    Any idea how I can solve this?

    Thanks,
    Nick

  4. #4
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: String Selection Popup

    Don't extract the form, build your own. I only created that as a simple example to show you how they work, it was not intended for actual use. You'll want to build your own:
    A) So you know how they function - why they do the things they do. Then if you need to make changes in the future you will know what to do.
    B) So you can build it the way you want it to be.

    Use my example to learn how it works, then build your own.

    ________________________________________________
    In general, subscript out of range occurs when you are trying to refer to something that does not exist. It can also occur when you are spelling a reference wrong. Are you sure you have an object named userform1?

  5. #5
    Registered User
    Join Date
    11-17-2011
    Location
    Ottawa
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: String Selection Popup

    Okay so I've deciphered the code enough to tweak it and incorporate it into my Workbook. It is really a handy form and much appreciated. I am however still struggling with one thing. I attached an error handler as seen in the code below.

    Please Login or Register  to view this content.
    This way if nothing is selected there isn't an error message. The only problem with the way I have this set up is that when the msg box pops up, the search is reset such that the user has to enter in the search parameters again. Is there any way to have the message box pop up without exiting the form?

    Thanks,

    Nick

    **Code Tags are now added. What different method would you suggest?**
    Last edited by touchofknowledge; 11-18-2011 at 04:07 PM. Reason: Code Tags

  6. #6
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: String Selection Popup

    I would suggest a different approach, but before we go further, I'm going to have to ask you to read the forum rules, then add code tags to your post. Once you have done this we will continue to help you find a resolution to your problem.

  7. #7
    Registered User
    Join Date
    11-17-2011
    Location
    Ottawa
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: String Selection Popup

    Code Tags are now added. What different method would you suggest?

  8. #8
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: String Selection Popup

    Thank You. Rather than using "On Error Resume Next", which can lead to dangerous side-effects if unexpected errors occur, why not just check and make sure an item has been selected from the listbox?

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    11-17-2011
    Location
    Ottawa
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: String Selection Popup

    Works like a charm. Thanks for all your help - I'll mark this as solved!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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