Export The data from Excel to Listbox

     

  • Export the data from excel to List box
  • Extract the data from Listbox to excel sheet
  •  

     

    Private Sub ToggleButton1_Click()

    Set SH = ThisWorkbook.Sheets("Output")
    SH.Activate
    SH.UsedRange.ClearContents
    Sheets("Sheet2").Range("A1:E1").Copy SH.Range("A1")
    r = 2
    For i = 0 To Me.ListBox1.ListCount - 1
    If Me.ListBox1.Selected(i) Then
    SH.Cells(r, 1).Value = Me.ListBox1.List(i, 0)
    SH.Cells(r, 2).Value = Me.ListBox1.List(i, 1)
    SH.Cells(r, 3).Value = Me.ListBox1.List(i, 2)
    SH.Cells(r, 4).Value = Me.ListBox1.List(i, 3)
    SH.Cells(r, 5).Value = Me.ListBox1.List(i, 4)
    r = r + 1
    End If
    Next
    Unload UserForm1

    End Sub




    Private Sub UserForm_Initialize()
    Set SH = ThisWorkbook.Sheets("Sheet2")
    LastRow = SH.Range("A" & Rows.Count).End(xlUp).Row
    With Me.ListBox1
    .Clear
    .Font.Size = 14
    .Font.Name = "Calibri"
    .ColumnCount = 5
    .ColumnHeads = True
    .RowSource = "Sheet2!A2:F" & LastRow
    .ListStyle = fmListStyleOption
    .MultiSelect = fmMultiSelectMulti
    .TextAlign = fmTextAlignCenter
    End With
    End Sub

    Download The Workbook