Consulting

Results 1 to 9 of 9

Thread: Solved: Userform Pop-up when opening excel

  1. #1
    VBAX Regular
    Joined
    Jul 2009
    Posts
    58
    Location

    Solved: Userform Pop-up when opening excel

    Hello
    Can u help to create a script that will popup a user form asking to select an option from the list. the option selected should then reflect in one of the cell in sheet2 and the form should close automatically..
    Regards
    Skopweb

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Show the form on workbook enter and get the value. Make sure that form gets hidden on close not unloaded.

    [vba]

    Private Sub Workbook_Open()

    With Userform1

    .Show
    Worksheets("Sheet1").Range("A2").Value = .cmbList.Value
    End With
    End Sub
    [/vba]

    This is workbook event code.
    To input this code, right click on the Excel icon on the worksheet
    (or next to the File menu if you maximise your workbooks),
    select View Code from the menu, and paste the code
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Jul 2009
    Posts
    58
    Location

    Userform Pop-up when opening excel

    Thanks XLD
    i tried using for the combobox and it works
    --------------------------------
    [VBA]Private Sub Workbook_Open()

    With UserForm1

    .Show
    Worksheets("Sheet1").Range("A2").Value = .ComboBox1.Value
    End With
    End Sub[/VBA]

    --------------------------------
    however can u tell me how can i enter the list of values to be selected from the combobox and once its selected the the form should close.
    the combo box should not take any other values than the one in the list


    Regards
    Skopweb

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Where are those values, in the code or a worksheet?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Regular
    Joined
    Jul 2009
    Posts
    58
    Location
    hello xld
    i just have 4 options to select but i have no preference if it should be in the code or in the list....
    can u let me know both of it so i can select the appropirate one...
    regards
    skopweb

  6. #6
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    With only 4 items, and assuming they don't change I would put then in the code
    [VBA]
    Private Sub UserForm_Initialize()
    ComboBox1.List = Array("Item1", "Item2", "Item3", "Item4")
    End Sub
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  7. #7
    VBAX Regular
    Joined
    Jul 2009
    Posts
    58
    Location
    thanks it works.....
    but once the item is selected.. can the form close automatically

  8. #8
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Yes.
    Just add Unload code to the Click event of the Combobox.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  9. #9
    VBAX Regular
    Joined
    Jul 2009
    Posts
    58
    Location
    thanks this works the way i wanted..
    regards
    skopweb

Posting Permissions

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