Consulting

Results 1 to 5 of 5

Thread: UserForm help, assigning variable from option button selection

  1. #1
    VBAX Newbie
    Joined
    Jul 2008
    Location
    Denver
    Posts
    5
    Location

    UserForm help, assigning variable from option button selection

    I'm trying to utilize UserForm option buttons to get info from user. I want to assign the option button selection to a variable that can be used in both the Filename and in a cell in the Excel File as part of a string of text not exclusive to the variable.

    See example UserForm code below. I want Month to be my variable. Assigned to my variable will be whatever the user selected.

    I get "Compile error: Argument not optional"

    [vba]
    If optionJanuary Then Month = "January"
    If optionFebruary Then Month = "February"
    If optionMarch Then Month = "March"
    If optionApril Then Month = "April"
    If optionMay Then Month = "May"
    If optionJune Then Month = "June"
    If optionJuly Then Month = "July"
    If optionAugust Then Month = "August"
    If optionSeptember Then Month = "September"
    If optionOctober Then Month = "October"
    If optionNovember Then Month = "November"
    If optionDecember Then Month = "December"[/vba]

    Please help.

  2. #2
    Don't you want to be using "ElseIf"?

  3. #3
    VBAX Mentor
    Joined
    Oct 2007
    Posts
    372
    Location
    Do you have an endif? It looks like you're supplying the only required argument for if's except the end...

  4. #4
    VBAX Mentor
    Joined
    Oct 2007
    Posts
    372
    Location
    and is month dim'd as string/

  5. #5
    VBAX Tutor david000's Avatar
    Joined
    Mar 2007
    Location
    Chicago
    Posts
    276
    Location

    Do you need option buttons?

    you could switch to a listbox or a combobox and get away easier.

    [vba]
    Private Sub UserForm_Initialize()
    Dim i As Integer
    With Me.ComboBox1
    For i = 1 To 12
    .AddItem MonthName(i)
    Next i
    End With
    End Sub


    Private Sub ComboBox1_Change()
    MsgBox ComboBox1.Value
    End Sub

    [/vba]

Posting Permissions

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