Userform ListBox not placing all the selection into the table

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,347
Office Version
  1. 365
Platform
  1. Windows
I have a Userform (Userform3) that has a ListBox (ListBox3) on it. The User is to select one or more items from the list and when they click the "Select" button (CommandButton1_Click) the selections from the ListBox is supposed to populate a table I have on a tab named Selected Tasks.

My issue is that it is only placing one of the selections in the table on tab Selected Tasks.

How can I modifiy this so that all selections are placed in the table. (FYI the table name is: Selected_Tasks)

Thanks for the Help

Code:
Private Sub CommandButton1_Click()
'Identifying Task(s)


'First Clear table

With Sheets("Selected Tasks").ListObjects("Selected_Tasks")
        
        'Check If any data exists in the table
        If Not .DataBodyRange Is Nothing Then
            'Clear Content from the table
            .DataBodyRange.ClearContents
        End If
        
    End With


'User Selects the Task(s)that they want the Cost Source, they are about to identify, to be applied to
'Move Selections to Tab: Selected Tasks

ListBox3.MultiSelect = fmMultiSelectMulti

'Loop through every item in the ListBox
For i = 0 To ListBox3.ListCount - 1

    'Check if the item was selected.
    If ListBox3.Selected(i) Then

        'This if section is determining if there was a selection

'Put all selected items in Column A
 With Sheets("Selected Tasks")
        If Len(.Range("A2").Value) = 0 Then
            .Range("A2").Value = ListBox3.List(i, 10)
        Else
            .Range("A" & .Rows.Count).End(xlUp).Offset(1).Value = ListBox3.List(i, 10)

        End If
    End With


    End If

Next i

UserForm3.Hide

'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
                UserFormX.Show vbModeless
                UserFormX.LabelProg.Width = 125
                UserFormX.LabelProg.Caption = "63%"
                DoEvents
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


'Refresh Source Selection
'RefreshCostSource
         Sheets("3 Source Selection").ListObjects(2).QueryTable.Refresh BackgroundQuery:=False

'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
                UserFormX.LabelProg.Width = 185
                UserFormX.LabelProg.Caption = "97%"
                DoEvents
            UserFormX.Hide
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

        Sheets("3 Source Selection").Activate

        MsgBox "In the table; select the row that has the Cost Source that you would like to use for this part and its identified task(s)"


End Sub

Private Sub CommandButton2_Click()

UserForm3.Hide

End Sub


Private Sub ListBox3_Click()

End Sub
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Comment: your code puts column 11 of the listbox in column A of your sheet.

Try this:
VBA Code:
  'Loop through every item in the ListBox
  For i = 0 To ListBox3.ListCount - 1
    If ListBox3.Selected(i) Then          'Check if the item was selected.
      With Sheets("Selected Tasks")       'Put all selected items in Column A
        lr = .Range("A:A").Find("*", , xlValues, xlPart, xlByRows, xlPrevious).Row + 1
        .Range("A" & lr).Value = ListBox3.List(i, 10)
      End With
    End If
  Next i
 
Upvote 0
Solution

Forum statistics

Threads
1,223,236
Messages
6,170,906
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top