【发布时间】:2014-05-08 09:26:28
【问题描述】:
i=19
With ListBox1
'clearing previous values from sheet
range(Cells(i + 2, 1).Address & ":" & Cells(endRwow, 7).Address).ClearContents
ListBoxArrSelected = vbNullString
For y = 0 To .ListCount - 1
If .Selected(y) Then
' concatenate all selected strings
ListBoxArrSelected = ListBoxArrSelected & "~" & ListBox1.List(y)
End If
Next y
' fill array with concatenated all selected strings spliting to rows
ListBoxArrSplitToRows = Split(ListBoxArrSelected, "~")
For UR = 1 To UBound(ListBoxArrSplitToRows, 1) + 1
' fill array with concatenated all selected strings spliting to colomuns
ListBoxArrSplitToCell = Split(ListBoxArrSplitToRows(UR - 1), "·")
For URc = 1 To UBound(ListBoxArrSplitToCell, 1) + 1
'paste to sheet
Cells(i + UR, 1).value = timeStr
Cells(i + UR, URc + 1).value = ListBoxArrSplitToCell(URc - 1)
Next URc
Next UR
End With
然后在列表框中选择> 100 个字段 excel 响应非常慢以将它们复制到工作表
如何加速这段代码?
【问题讨论】:
-
请举例说明
-
这里不要连接 'For y = 0 To .ListCount - 1 If .Selected(y) Then ' 连接所有选中的字符串 ListBoxArrSelected = ListBoxArrSelected & "~" & ListBox1.List(y) End If接下来 y' 将值放入字典或数组中。因此,下次您不必使用“~”拆分所有值并为每个值进行迭代。这将节省您的时间。