每个项目都有一个button来将数量添加到另一个订单列表。 偏移不起作用

我有一个命令button被设置为每个产品线。 总的来说,我在Sheet 1上有20多个button。

如果我点击数量大于1的商品,商品名称将被复制并粘贴到订单列表页面。

我尝试使用“偏移量”将其粘贴到“订单列表”中的A2行A下的空白列中。

但是,我点击另一个button后,它只replaceA2而不是粘贴到A3。

前两个button的代码细节如下(所有20个button应该是相同的代码,因为它们不会按顺序点击),只要它拿起空白列就可以了:

Private Sub CommandButton1_Click() Dim wb As Workbook Dim wsSource As Worksheet Dim wsDest As Worksheet Set wb = ActiveWorkbook Set wsSource = wb.Sheets("Sheet1") Set wsDest = wb.Sheets("Order List") 'Stop if report not filled in fully If wsSource.Range("G28").Value < 1 Then MsgBox "Please Amend Quantity" Exit Sub End If wsSource.Range("B28").Copy wsDest.Range("A1").Offset(1,0) wsDest.Range("A:D").EntireColumn.AutoFit End Sub Private Sub CommandButton2_Click() Dim wb As Workbook Dim wsSource As Worksheet Dim wsDest As Worksheet Set wb = ActiveWorkbook Set wsSource = wb.Sheets("Sheet1") Set wsDest = wb.Sheets("Order List") 'Stop if report not filled in fully If wsSource.Range("G28").Value < 1 Then MsgBox "Please Amend Quantity" Exit Sub End If wsSource.Range("B28").Copy wsDest.Range("A1").Offset(1,0) wsDest.Range("A:D").EntireColumn.AutoFit End Sub 

请build议我。 非常感谢

使用它代替它将find最后使用的单元格,然后向下移动到下一个单元格(您的代码从不更新目标单元格,它固定在A2)。 这些button是什么 – 你应该能够避免重复你的代码20次。

 wsSource.Range("B28").Copy wsDest.Range("A" & rows.count).end(xlup).Offset(1,0)