Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Teaching myself VBA

Status
Not open for further replies.

lankaw

Programmer
Sep 17, 2015
10
CA
Hi Guys ,

I'm new to vba and coding in excel and ive gotten myself into quite the pickle

Simply put , i have 5 check boxes on my user form thereby creating 120 possible combinations which each will give me a combination msgbox of the text fields the check boxes are in front off. .

Is there a easier way to code this without doing 120 nested if's lol.

thanks !
 
Checkboxes is a waste of place and, as Andy pointed, hard to modify.
Sample code for multiselect listbox (ListBox1) + command button (CommandButton1):
Code:
Private Sub UserForm_Initialize()
' fill the list with a - e
With Me.ListBox1
    For i = 1 To 5
        .AddItem Chr(96 + i)
    Next i
End With
End Sub

Private Sub CommandButton1_Click()
Dim bSelected As Boolean, s As String
bSelected = False
' check and display selection
With Me.ListBox1
    For i = 0 To .ListCount - 1
        If .Selected(i) Then
            If bSelected Then
                s = s & vbNewLine & .List(i)
            Else
                bSelected = True
                s = .List(i)
            End If
        End If
    Next i
End With
If bSelected Then MsgBox s Else MsgBox "Nothing has been checked."
End Sub


combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top