VBA - Add Multi-Line Items to Table

sprigelz

Board Regular
Joined
Jan 7, 2016
Messages
98
Office Version
  1. 365
Platform
  1. Windows
Good afternoon,

I used the following tutorial to create a Multiple Selection ListBox Userform - Excel Easy - Multi ListBox Selection

I would like to update the following VBA code to be able to create each new line item in ListBox2 and the below dropdown & textboxes into individual rows. This code presently works on another of my userforms to add a single line of training to the table.

ListBox1 = List of all Employees
ListBox2 = Selection of bulk Employees
ComboBox1 = Training Event
TextBox1 = Training Date
ComboBox2 = Training Type


VBA Code:
'Transfer Data to TrainingTrack tbl
Dim tbl As ListObject
Dim ws As Worksheet
Dim lrow As Range
Dim lrow2 As Long


Set tbl = Sheets("Training Tracker").ListObjects("TrainingTrack")

    If tbl.ListRows.Count > 0 Then

        Set lrow = tbl.ListRows(tbl.ListRows.Count).Range
        For col = 1 To lrow.Columns.Count
            If Trim(CStr(lrow.Cells(1, col).Value)) <> "" Then
                tbl.ListRows.Add
                Exit For
            End If
        Next
    End If

    lrow2 = tbl.ListRows.Count

     tbl.DataBodyRange(lrow2, 1).Value = ComboBox1.Value
     tbl.DataBodyRange(lrow2, 2).Value = Application.WorksheetFunction.Index(Sheets("Employee List").Range("D1:D1000"), Application.WorksheetFunction.Match(ComboBox1.Value, Sheets("Employee List").Range("K1:K1000"), 0))
     tbl.DataBodyRange(lrow2, 3).Value = Application.WorksheetFunction.Index(Sheets("Employee List").Range("E1:E1000"), Application.WorksheetFunction.Match(ComboBox1.Value, Sheets("Employee List").Range("K1:K1000"), 0))
     tbl.DataBodyRange(lrow2, 4).Value = Application.WorksheetFunction.Index(Sheets("Employee List").Range("C1:C1000"), Application.WorksheetFunction.Match(ComboBox1.Value, Sheets("Employee List").Range("K1:K1000"), 0))
     tbl.DataBodyRange(lrow2, 5).Value = ComboBox2.Value
     tbl.DataBodyRange(lrow2, 6).Value = TextBox1.Value
     tbl.DataBodyRange(lrow2, 7).Value = TextBox2.Value
     tbl.DataBodyRange(lrow2, 8).Value = ComboBox3.Value
     tbl.DataBodyRange(lrow2, 9).Value = Application.WorksheetFunction.Index(Sheets("Employee List").Range("H1:H1000"), Application.WorksheetFunction.Match(ComboBox1.Value, Sheets("Employee List").Range("K1:K1000"), 0))
     tbl.DataBodyRange(lrow2, 10).Value = Application.WorksheetFunction.Index(Sheets("Employee List").Range("J1:J1000"), Application.WorksheetFunction.Match(ComboBox1.Value, Sheets("Employee List").Range("K1:K1000"), 0))
     tbl.DataBodyRange(lrow2, 11).Value = Worksheets("Dashboard").Range("C15").Value
     tbl.DataBodyRange(lrow2, 12).Value = Now
 

Attachments

  • Screenshot 2022-08-23 123607.png
    Screenshot 2022-08-23 123607.png
    61.3 KB · Views: 53

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Forum statistics

Threads
1,223,238
Messages
6,170,939
Members
452,368
Latest member
jayp2104

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