[英]I want to copy a range of cells from one sheet to another sheet in the next blank row
[英]Copy a range of cells from one sheet and insert into next empty row
我想将一行(A1:B1)中的数据复制到另一张纸的下一个空行中,并删除该行。 我尝试了以下代码,但仅适用于特定的单元格。 不确定如何为下一个空行执行此操作。 有谁能够帮助我?
我也希望每当(A1:B1)被编辑时都会发生这种情况。 只要编辑了A1:B1,宏就应该初始化自己。
Sub Macro5()
'
' Macro5 Macro
'
' Keyboard Shortcut: Ctrl+w
'
Range("A1:B1").Select
Selection.Copy
Sheets("Sheet1").Select
Range("A32").Select
ActiveSheet.Paste
Sheets("Sheet2").Select
Application.CutCopyMode = False
Selection.ClearContents
End Sub
在主工作表的代码模块(这是您要复制的代码)中,放置以下例程:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count = 1 Then
If Target.Column < 3 Then
If Target.Row < 2 Then
On Error Resume Next
Application.EnableEvents = False
With Sheet2
.Cells(.Rows.Count, "a").End(xlUp)(2).Resize(, 2) = [a1:b1].Value
[a1:b1].Delete xlUp
End With
End If
End If
End If
Application.EnableEvents = True
End Sub
注意:这有效地满足了您的要求,但似乎是一个奇怪的要求...
更新
看完OP的工作簿后,这是我提供的过程:
Sub Transfer2ndSheetRow1To1stSheet()
With Sheet2
If .[counta(1:1)] Then
Sheet1.Cells(.Rows.Count, "a").End(xlUp)(2).EntireRow = .[1:1].Value
.[1:1].Delete xlUp
End If
End With
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.