Results 1 to 9 of 9

Thread: How To Close A UserForm With A CommandButton

  1. #1
    Senior Member
    Join Date
    Jul 2013
    Posts
    102
    Rep Power
    12

    How To Close A UserForm With A CommandButton

    OK I am having my first attempt with creating a Userform.I am reading up on how to create.
    1. How do I add entries into the dropdown box`s on the userform
    2. How to I get the userform to open when I press the command button.I tried with a macro recorder but I did not get it to open successfully
    I will keep reading and hopefully get some answers
    Jeff
    Attached Files Attached Files

  2. #2
    Senior Member
    Join Date
    Jul 2013
    Posts
    102
    Rep Power
    12
    Ok
    I got a small code to open the userform.This seems to work but the code I have used to close the userform gives error.Why does it give error and am I on the correct path so far?
    Jeff
    Attached Files Attached Files

  3. #3
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    The code to unload from within a routine in the user-form is not Unload.Me, it's
    Code:
    Unload Me
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  4. #4
    Senior Member
    Join Date
    Jul 2013
    Posts
    102
    Rep Power
    12
    How do I make entries in the user forms drop down boxs

  5. #5
    Senior Member
    Join Date
    Jul 2013
    Posts
    102
    Rep Power
    12
    OK....I have added a list of entries into the first combobox.....Is this the correct way to add entries into a combobox..if yes,iwill proceed with the rest
    Jeff
    Attached Files Attached Files

  6. #6
    Member
    Join Date
    May 2013
    Posts
    31
    Rep Power
    0
    A named Range for the ListRow works fine. You can also use ComboBox1.List = somearray() or add one item at a time with ComboBox1.AddItem method.

    If you are going to use a Range name, add a dynamic range or reset the named range in the Userform's Initialize event.

  7. #7
    Senior Member
    Join Date
    Jul 2013
    Posts
    102
    Rep Power
    12
    Thank you Kenneth.Would you have a sample file of your mentioned methods.This would be appreciated.Jeff

  8. #8
    Member
    Join Date
    May 2013
    Posts
    31
    Rep Power
    0
    You only need one way to solve a problem. In any case, this should show you some other methods.

    Notice that I added ken as the first item after I added other items. I then added the last 3 items from the named range. That method can be used to get any range in a dynamic way.

    While adding the 3 items created duplicates, to remove them, is another issue. It is a common question. If you need to do that, search this forum or the web or start a new thread. There again, there are several ways to solve the problem.

    Code:
    Private Sub UserForm_Initialize()
      Dim c As Range, r As Range
      With ComboBox1
        .RowSource = vbNullString
        '.RowSource = "Machines"
        .List = Range("Machines").Value
        .AddItem "Ken", 0
        
        Set r = Worksheets("Lists").Range("A7", _
          Worksheets("Lists").Range("A" & Rows.Count).End(xlUp))
        For Each c In r
          .AddItem c.Value, -1
        Next c
      End With
    End Sub

  9. #9
    Senior Member
    Join Date
    Jul 2013
    Posts
    102
    Rep Power
    12
    Thank you

    Could you please explain - If you are going to use a Range name, add a dynamic range or reset the named range in the Userform's Initialize event.

    Jeff

Similar Threads

  1. Macro To Close All CSV Files
    By Howardc in forum Excel Help
    Replies: 5
    Last Post: 03-15-2014, 05:24 PM
  2. One userform and 60 Combo Boxes
    By k0st4din in forum Excel Help
    Replies: 11
    Last Post: 04-25-2013, 09:55 AM
  3. set ListView on userform
    By Mahesh in forum Excel Help
    Replies: 3
    Last Post: 12-04-2012, 08:50 AM
  4. Replies: 2
    Last Post: 12-12-2011, 01:51 PM
  5. Timer to close excel workbook
    By leopaulc in forum Excel Help
    Replies: 5
    Last Post: 10-24-2011, 12:31 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •