我是VBA的新手。我正在尝试将单元格J9:J22和单元格E7从“最终输出表”复制到“已保存结果”表。下面是我写的宏。它没有显示任何错误,但在运行它时,单个单元格E7正在粘贴,但是J9:J22不是,它显示为空白。你能帮忙吗?
Private Sub CommandButton1_Click()
Dim noofboxes As Range, Depot As String
Worksheets("Final Output Sheet").Select
Set noofboxes = Worksheets("Final Output Sheet").Range("J9:J22")
Depot = Range("E7")
Worksheets("Saved Results").Select
Worksheets("Saved Results").Range("A1").Select
If Worksheets("Saved Results").Range("A1").Offset(1, 0) <> "" Then
Worksheets("Saved Results").Range("A1").End(xlDown).Select
End If
ActiveCell.Offset(1, 0).Select
ActiveCell.Value = Depot
ActiveCell.Offset(0, 3).Activate
ActiveCell.Value = noofboxes
End Sub
答案 0 :(得分:0)
这个怎么样:
Private Sub CommandButton1_Click()
Dim target As Range
With Worksheets("Saved Results")
If .Range("A1").Offset(1, 0) <> "" Then
Set target = .Range("A1").End(xlDown)
Else
Set target = .Range("A1")
End If
Worksheets("Final Output Sheet").Range("E7").Copy Destination:=target.Offset(1, 0)
Worksheets("Final Output Sheet").Range("J9:J22").Copy Destination:=target.Offset(0, 3)
End With
End Sub