+ Reply to Thread
Results 1 to 5 of 5

Making a list box of checkboxes

  1. #1
    David Gerstman
    Guest

    Making a list box of checkboxes

    I want to create a listbox of choices. When the user clicks on checkboxes
    corresponding to a choice I will use those choices for further processing.
    This is what I have so far; how do I display the requisite checkboxes for the
    choices?

    Sub load_names()
    Dim emp_range As Range
    Worksheets(1).Activate
    Set emp_range = ActiveSheet.Range("b2", Range("b2").End(xlDown))
    ind = 1
    For Each c In emp_range
    UserForm1.ListBox1.AddItem c.Value
    ind = ind + 1
    Next c
    UserForm1.Show
    End Sub

    thanks,
    David

  2. #2
    moi
    Guest

    Re: Making a list box of checkboxes

    In the properties windos, set the ListStyle to fmListStyleOption and set
    MultiSelect to fmMultiSelectMulti.


    "David Gerstman" <[email protected]> schreef in bericht
    news:[email protected]...
    >I want to create a listbox of choices. When the user clicks on checkboxes
    > corresponding to a choice I will use those choices for further processing.
    > This is what I have so far; how do I display the requisite checkboxes for
    > the
    > choices?
    >
    > Sub load_names()
    > Dim emp_range As Range
    > Worksheets(1).Activate
    > Set emp_range = ActiveSheet.Range("b2", Range("b2").End(xlDown))
    > ind = 1
    > For Each c In emp_range
    > UserForm1.ListBox1.AddItem c.Value
    > ind = ind + 1
    > Next c
    > UserForm1.Show
    > End Sub
    >
    > thanks,
    > David




  3. #3
    Dave Peterson
    Guest

    Re: Making a list box of checkboxes

    I created a small userform with a listbox and 2 buttons on it.

    This is the code I had behind the form:

    Option Explicit
    Private Sub CommandButton1_Click()
    Unload Me
    End Sub
    Private Sub CommandButton2_Click()

    Dim iCtr As Long

    With Me.ListBox1
    For iCtr = 0 To .ListCount - 1
    If .Selected(iCtr) Then
    'do what you want
    MsgBox .List(iCtr)
    End If
    Next iCtr
    End With

    'unload me 'get out?

    End Sub
    Private Sub UserForm_Initialize()

    Dim Emp_Range As Range
    Dim myCell As Range

    With Worksheets(1)
    Set Emp_Range = .Range("b2", .Range("b2").End(xlDown))
    End With

    For Each myCell In Emp_Range
    Me.ListBox1.AddItem myCell.Value
    Next myCell

    With Me.ListBox1
    .ListStyle = fmListStyleOption
    .MultiSelect = fmMultiSelectMulti
    End With
    End Sub

    The .liststyle of fmliststyleoption gives a nice checkbox. The .multiselect
    allows more than one selection.



    David Gerstman wrote:
    >
    > I want to create a listbox of choices. When the user clicks on checkboxes
    > corresponding to a choice I will use those choices for further processing.
    > This is what I have so far; how do I display the requisite checkboxes for the
    > choices?
    >
    > Sub load_names()
    > Dim emp_range As Range
    > Worksheets(1).Activate
    > Set emp_range = ActiveSheet.Range("b2", Range("b2").End(xlDown))
    > ind = 1
    > For Each c In emp_range
    > UserForm1.ListBox1.AddItem c.Value
    > ind = ind + 1
    > Next c
    > UserForm1.Show
    > End Sub
    >
    > thanks,
    > David


    --

    Dave Peterson

  4. #4
    David Gerstman
    Guest

    Re: Making a list box of checkboxes

    Thank you so much!
    David

    "moi" wrote:

    > In the properties windos, set the ListStyle to fmListStyleOption and set
    > MultiSelect to fmMultiSelectMulti.
    >
    >
    > "David Gerstman" <[email protected]> schreef in bericht
    > news:[email protected]...
    > >I want to create a listbox of choices. When the user clicks on checkboxes
    > > corresponding to a choice I will use those choices for further processing.
    > > This is what I have so far; how do I display the requisite checkboxes for
    > > the
    > > choices?
    > >
    > > Sub load_names()
    > > Dim emp_range As Range
    > > Worksheets(1).Activate
    > > Set emp_range = ActiveSheet.Range("b2", Range("b2").End(xlDown))
    > > ind = 1
    > > For Each c In emp_range
    > > UserForm1.ListBox1.AddItem c.Value
    > > ind = ind + 1
    > > Next c
    > > UserForm1.Show
    > > End Sub
    > >
    > > thanks,
    > > David

    >
    >
    >


  5. #5
    David Gerstman
    Guest

    Re: Making a list box of checkboxes

    Thank you too. That helped a lot too.
    David

    "Dave Peterson" wrote:

    > I created a small userform with a listbox and 2 buttons on it.
    >
    > This is the code I had behind the form:
    >
    > Option Explicit
    > Private Sub CommandButton1_Click()
    > Unload Me
    > End Sub
    > Private Sub CommandButton2_Click()
    >
    > Dim iCtr As Long
    >
    > With Me.ListBox1
    > For iCtr = 0 To .ListCount - 1
    > If .Selected(iCtr) Then
    > 'do what you want
    > MsgBox .List(iCtr)
    > End If
    > Next iCtr
    > End With
    >
    > 'unload me 'get out?
    >
    > End Sub
    > Private Sub UserForm_Initialize()
    >
    > Dim Emp_Range As Range
    > Dim myCell As Range
    >
    > With Worksheets(1)
    > Set Emp_Range = .Range("b2", .Range("b2").End(xlDown))
    > End With
    >
    > For Each myCell In Emp_Range
    > Me.ListBox1.AddItem myCell.Value
    > Next myCell
    >
    > With Me.ListBox1
    > .ListStyle = fmListStyleOption
    > .MultiSelect = fmMultiSelectMulti
    > End With
    > End Sub
    >
    > The .liststyle of fmliststyleoption gives a nice checkbox. The .multiselect
    > allows more than one selection.
    >
    >
    >
    > David Gerstman wrote:
    > >
    > > I want to create a listbox of choices. When the user clicks on checkboxes
    > > corresponding to a choice I will use those choices for further processing.
    > > This is what I have so far; how do I display the requisite checkboxes for the
    > > choices?
    > >
    > > Sub load_names()
    > > Dim emp_range As Range
    > > Worksheets(1).Activate
    > > Set emp_range = ActiveSheet.Range("b2", Range("b2").End(xlDown))
    > > ind = 1
    > > For Each c In emp_range
    > > UserForm1.ListBox1.AddItem c.Value
    > > ind = ind + 1
    > > Next c
    > > UserForm1.Show
    > > End Sub
    > >
    > > thanks,
    > > David

    >
    > --
    >
    > Dave Peterson
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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