我想从 sheet1 复制一些单元格并将它们插入到 sheet2 的标题之间。我写了下面的代码和一个按钮来执行它,但问题是每次我点击按钮时,它都会插入新的标题。我怎样才能改变它?
lastColumnS1 = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Column
Sheets("Sheet1").Select
Range(Cells(1, 3), Cells(1, lastColumnS1)).Select
Selection.Copy
Sheets("Sheet2").Select
lastColumn3 = ActiveSheet.Cells.SpecialCells(xlLastCell).Column
Range("B1").Select
Selection.Insert Shift:=xlToRight
Range(Cells(2, lastColumn3), Cells(3, lastColumn3)).Select
Selection.Cut
lastColumn3_ = ActiveSheet.Cells.SpecialCells(xlLastCell).Column
Range(Cells(2, lastColumn3_), Cells(3, lastColumn3_)).Select
ActiveSheet.Paste
样本数据
Sheet1:
ID Name x y z
1 AA
2 BB
Sheet2:
ID Name
3 KK
6 LL
desired result of Sheet2:
ID x y z Name
3 KK
6 LL