【发布时间】:2015-08-21 23:05:17
【问题描述】:
所以我在一个又一个论坛(包括堆栈)搜索谷歌和论坛试图解决这个问题。我想要做的就是有一个 ActiveX 按钮将列表框的内容导出到 Excel 中的某个范围。
以下是将 ListBox1 中的项目添加到 ListBox2 的代码。在所有需要的项目都移动到 ListBox2 之后,所述 ActiveX 按钮 (SomeButton_Click) 会将 ListBox2 中的所有项目导出到从 range("a1") 开始的 "Sheet15"。
(请注意,这是一个不在实际表单上的 ActiveX 列表框。它在工作表中)
Public Sub BTN_MoveSelectedRight_Click()
Dim iCtr As Long
Dim n As Long, lRow As Long
Dim cStartCell As Range
For iCtr = 0 To Me.ListBox1.ListCount - 1
If Me.ListBox1.Selected(iCtr) = True Then
Me.ListBox2.AddItem Me.ListBox1.List(iCtr)
End If
Next iCtr
For iCtr = Me.ListBox1.ListCount - 1 To 0 Step -1
If Me.ListBox1.Selected(iCtr) = True Then
Me.ListBox1.RemoveItem iCtr
End If
Next iCtr
End Sub
下面是执行导出的按钮:
Public Sub SomeButton_Click()
'What code can I put here to perform the export to abovementioned range?
End sub
任何帮助都将不胜感激,因为我花了几个小时试图弄清楚这一点(尽管我不想真正承认这一点,但这是真的)
谢谢!
【问题讨论】: