【发布时间】:2019-09-18 05:39:04
【问题描述】:
我正在尝试将用户窗体上多列列表框中的所有选定项目添加到我的 Excel 工作表中。这些是我目前正在使用的代码:
Dim lrow As Range
Dim wst As Worksheet
Dim lo As ListObject
Dim lr As ListRow
Application.ScreenUpdating = False
Dim xRow As Integer, intItem As Integer
Set wst = Sheets("TRAININGS PROFILE")
wst.Activate
wst.Range("B4").Select
For intItem = 0 To listbox1.ListCount - 1
If listbox1.Selected(intItem) = True Then
Set lo = wst.ListObjects(1)
Set lr = lo.ListRows.Add
ActiveCell.Offset(0, 3).Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 0)
ActiveCell.Offset(0, 4).Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 1)
ActiveCell.Offset(1, 0).Select
End If
Next intItem
Application.ScreenUpdating = True
此代码有效,但问题是它仅保存我的列表框中的最后一个选定项,它不会循环遍历每个选定项。请帮忙。
【问题讨论】: