我将列表框中7列的数据传输到工作表中,转移到选定的单元格中(A20:G29)。数据传输到下一个可用的单元格,而不是A20:G29
这是我的代码:
Private Sub cmdAdd_Click()
Dim addme As Range
Dim x As Integer
Set addme = Sheet2.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
For x = 0 To Me.lstSelector.ListCount - 1
If Me.lstSelector.Selected(x) Then
addme = Me.lstSelector.List(x)
addme.Offset(0, 1) = Me.lstSelector.List(x, 1)
addme.Offset(0, 2) = Me.lstSelector.List(x, 2)
addme.Offset(0, 3) = Me.lstSelector.List(x, 3)
addme.Offset(0, 4) = Me.lstSelector.List(x, 4)
addme.Offset(0, 5) = Me.lstSelector.List(x, 5)
addme.Offset(0, 6) = Me.lstSelector.List(x, 6)
Set addme = addme.Offset(1, 0)
End If
Next x
For x = 0 To Me.lstSelector.ListCount - 1
If Me.lstSelector.Selected(x) Then Me.lstSelector.Selected(x) = False
Next x
End Sub
Private Sub cmdclose_Click()
Unload Me
End Sub
Private Sub lstSelector_Click()
End Sub
我需要建议
答案 0 :(得分:0)
此行建立数据输出的起始范围/单元格:
Set addme = Sheet2.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
这是一种相对粗略但常用的方法,可以找到范围内的最后一个单元格。因此,这是有道理的,您的过程将始终“转移到下一个可用的单元格”,而不是其他特定范围的单元格。
请改为尝试:
Set addme = Sheet2.Range("A20")