+ Reply to Thread
Results 1 to 5 of 5

ComboBoxes with Select Case

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    04-30-2013
    Location
    D.C.
    MS-Off Ver
    Excel 2010
    Posts
    192

    ComboBoxes with Select Case

    I am attempting to write a simple basic userform with two comboboxes with select case to learn how it works before I add it to my extensive report.

    This uerform has two comboboxes with submit and cancel buttons, that's it.

    I wrote the code here, focusing on combobox 1 for now. (Combo box 2 will be added later).

    After executing the code in immediate window, it says "Compile Error: Invalid use of property". I wonder why.

    Formula: copy to clipboard
    Private Sub Yr_Change()

    Select Case Me.Yr.Value
    Case "2012"
    MsgBox ("Hello, World!")
    Case "2013"
    MsgBox ("Whaa...?")
    Case "2014"
    MsgBox ("Howdy 2014!")
    End Select

    End Sub
    Private Sub UserForm_Initialize()

    With Me.Yr
    .AddItem "2012"
    .AddItem "2013"
    .AddItem "2014"
    End With

    End Sub
    Private Sub cmdCancel()
    Unload Me
    End Sub

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: ComboBoxes with Select Case

    What code did you put in the Immediate Window?

    That code should be in the Userfom module with one adjusment.
    Private Sub cmdCancel_Click()
    
        Unload Me
    
    End Sub
    When I do that and run the form it works as expected, displaying the relevant message based on what's selected in the combobox.
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    04-30-2013
    Location
    D.C.
    MS-Off Ver
    Excel 2010
    Posts
    192

    Re: ComboBoxes with Select Case

    TestForm was what I put in the immediate window to run TestForm macro below:

    Formula: copy to clipboard
    Sub TestForm()
    TestForm.Show
    End Sub

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: ComboBoxes with Select Case

    Not a good idea to name both the sub and the userform TestForm.

  5. #5
    Forum Contributor
    Join Date
    04-30-2013
    Location
    D.C.
    MS-Off Ver
    Excel 2010
    Posts
    192

    Re: ComboBoxes with Select Case

    -______-

    Noob mistake!!! HahaH Thanks, Norie!!

    SOLVED.

+ 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. [SOLVED] Need the proper syntax to use Case/Select Case in vba properly.
    By rbion in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-16-2013, 02:34 PM
  2. [SOLVED] Disregard case in VBA code. (UCase, LCase, Select Case)
    By Orestees in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 09-07-2012, 12:12 PM
  3. Case Select compile error "Case without case select"
    By coasterman in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-23-2012, 06:50 AM
  4. Case Select....The alternative method for long "Select Case"
    By kimyap in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-22-2008, 01:24 AM
  5. Select case / case is, multiple arguments
    By Werner Rohrmoser in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-03-2006, 07:00 AM

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