问题描述
她是业余的,所以请和我一起忍受。我正在尝试编译VBA代码,该代码运行一个用户窗体,其中的列表框填充了worksheet1
中的9列和100行表。用户仅选择列表框中需要报表的项目,然后将其复制到工作表2中。
在这个网站上已有6年历史的帖子的帮助下,我设法使用数组和公共函数来选择选定的行,然后将其输出到worksheets2
。如下:
Private Sub CommandButton1_Click()
Dim SelectedItems() As Variant
Dim i As Integer
Dim emptyrow As Integer
wsTarget.Activate
Range("A1").Select
SelectedItems = GetSelectedRisks(RiskList)
emptyrow = 15
For i = LBound(SelectedItems) To UBound(SelectedItems)
wsTarget.Cells(emptyrow,2).Value = SelectedItems(i)
emptyrow = emptyrow + 1
Next
End Sub
Public Function GetSelectedRisks(lBox As MSForms.ListBox) As Variant
Dim tmpArray() As Variant
Dim i As Integer
Dim SelectionCounter As Integer
SelectionCounter = -1
For i = 0 To lBox.ListCount - 1
If lBox.Selected(i) = True Then
SelectionCounter = SelectionCounter + 1
ReDim Preserve tmpArray(SelectionCounter)
tmpArray(SelectionCounter) = lBox.List(i)
End If
Next
但是,我只能算出第一栏的操作方法。我只是想不出如何将其他列放入数组,然后再次退出。
我应该使用数组还是要使其变得复杂,即是否应该仅使用循环,如果选择了entirerow.copy
类型的东西?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)