Running Userforms in functions.

  • Hello,

    I have been working on this problem for a while now and have no idea how to do this.

    To briefly explain what it does is basically it reads through a log and takes the object of each entry and sorts it into categories (just for this example we will use car, plants, insect). At this time it is impossible to predict every possible object for each of these categories I am writing the script to learn from entries it doesn't recognize. To do this I want the function to open up a user form mid function prompting the user to select what category this new object falls into.

    Now for the issue. I can not figure out how to have a user form open up with three buttons and the function that opened up the user form be able to recognize what the user selected. I am only familiar with running code specifically in the user form and not being able to use the information in the user form in the main worksheet functions.

    If any one has any ideas or any other ideas on how I can work this problem please let me know. Thank you.

  • Re: Running Userforms in functions.

    Lets simplify things so the userform has two TextBoxes an OK button and a cancel button. The code for your Userform would look like

    Private Sub butOK_Click()
        Me.Tag = "OK"
    End Sub
    Private Sub butCancel_Click()
        Unload Me
    End Sub

    The code for your function would look like

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!