将多列列表框导出到特定范围

exporting multicolumn listbox to specific range

背景信息:我有一个用户表单,其中包含一个 2 列列表框和一个命令按钮

我想通过按钮将列表框中的所有项目(从两列)导出到 sheet。我正在考虑使用循环从列表框中获取所有信息,但不知何故它不起作用。当 运行 时,它只给我列表框中的第一行,而不是其他行。

Private Sub CommandButton1_Click()

Dim i, t As Double
Dim inputrow As Long
Dim sh As Worksheet
Dim lastrow As Long

Set sh = Sheets("sheet1")

lastrow = sh.Range("A" & Application.Rows.Count).End(xlUp).Row + 1

i = ListBox2.ListCount

For inputrow = lastrow To lastrow + i

    For t = 0 To i
    
        sh.Range("A" & inputrow).Value = ListBox2.List(t, 0)
        sh.Range("B" & inputrow).Value = ListBox2.List(t, 1)
            
    Exit For
     
    Next t

Exit For

Next inputrow

end sub

尝试关注子

Private Sub CommandButton1_Click()
Dim lRow As Long, i As Long
Dim sh As Worksheet
Dim Rng As Range

Set sh = Sheets("Sheet1")
lRow = sh.Cells(sh.Rows.Count, "A").End(xlUp).Row

    Set Rng = Range("A" & lRow)
    For i = 0 To Me.ListBox1.ListCount - 1
        Rng.Offset(i + 1, 0) = Me.ListBox1.List(i, 0)
        'sh.Range("A" & lRow + i + 1) = Me.ListBox1.List(i, 0)
        
        Rng.Offset(i + 1, 1) = Me.ListBox1.List(i, 1)
        'sh.Range("B" & lRow + i + 1) = Me.ListBox1.List(i, 0)
    Next i

Set Rng = Nothing
Set sh = Nothing
End Sub