我在用户表单中有一个列表框。当用户选择并单击“导出到Excel”按钮时,它将选择的项目导出到第7列。
我要将单个选择导出到第七列和第八列。
当前工作代码
Set wf = Application.WorksheetFunction
Set addlist = Sheet1.Cells(Rows.Count, 7).End(xlUp).Offset(1, 0)
For x = 1 To WortSelector.ListCount - 1
If Me.WortSelector.Selected(x) Then
addlist = Me.WortSelector.List(x)
Set addlist = addlist.Offset(1, 0)
End If
Next x
基本上我想要
Set addlist = Sheet.Cells(Rows.Count, 8).End(xlUp).Offset(1,0)
答案 0 :(得分:0)
两个不同的列不能使用相同的变量名。
Set wf = Application.WorksheetFunction
Set addlist = Sheet1.Cells(Rows.Count, 7).End(xlUp).Offset(1, 0)
Set addlist2 = Sheet1.Cells(Rows.Count, 8).End(xlUp).Offset(1, 0)
For x = 1 To WortSelector.ListCount - 1
If Me.WortSelector.Selected(x) Then
addlist = Me.WortSelector.List(x)
Set addlist = addlist.Offset(1, 0)
addlist2 = Me.WortSelector.List(x)
Set addlist2 = addlist2.Offset(1, 1)
End If
Next x
希望这会有所帮助。
或仅使第7列和第8列相等(在Next x之后):
Worksheets(1).Range("H:H").Value = Worksheets(1).Range("G:G").Value