我想复制'Sheet1'中的数据($ A:$ N;可能会波动),选择数据范围并将其粘贴到'Sheet3'中。
我还需要复制'Sheet2'中没有第一行的数据(与'Sheet1'相同的标题)并将其粘贴到'Sheet1'的数据下面,现在在'Sheet3'中。
Sub CopyPaste()
Sheets("PC_VIEWS").Select
Range("A1:Q231").Select
Selection.Copy
Sheets("PC_LTC_VIEWS").Select
Range("A1").Select
ActiveSheet.Paste
Range("A1").Select
Selection.End(xlDown).Select
Range("A232").Select
Sheets("LTC_VIEWS").Select
Range("A1").Select
Application.CutCopyMode = False
Range("A1:M1264").Select
Selection.Copy
Sheets("PC_LTC_VIEWS").Select
ActiveSheet.Paste
End Sub
我对其他解决方案持开放态度!
答案 0 :(得分:1)
这段代码就足够了。试试吧。
Public Sub CopyAndPaste()
Dim firstRowCount, secondRowCount As Integer
'Copy from "PC_VIEWS" sheet.
Sheets("PC_VIEWS").Select
'Getting the last row from "PC_VIEWS" sheet.
firstRowCount = Range("A:Q").SpecialCells(xlLastCell).row
Range("A1:Q" & firstRowCount).Select
Selection.Copy
'Paste to "PC_LTC_VIEWS" sheet.
Sheets("PC_LTC_VIEWS").Select
Range("A1").Select
ActiveSheet.Paste
'Reset clipboard
Application.CutCopyMode = False
'Copy from "LTC_VIEWS" sheet.
Sheets("LTC_VIEWS").Select
'Getting the last row from "LTC_VIEWS" sheet.
secondRowCount = Range("A:Q").SpecialCells(xlLastCell).row
Range("A2:Q" & secondRowCount).Select
Selection.Copy
'Paste to "PC_LTC_VIEWS" sheet.
Sheets("PC_LTC_VIEWS").Select
Range("A" & firstRowCount + 1).Select
ActiveSheet.Paste
'Reset clipboard
Application.CutCopyMode = False
End Sub