古詩詞大全網 - 四字成語 - VBA用usedrange復制,但是不復制第壹行表頭數據?

VBA用usedrange復制,但是不復制第壹行表頭數據?

既然是使用 UsedRange,但又想排除第壹行,那就需要知道總行數和總列數,然後自己再重新定義復制區域即可。

比如:

Sub test()

Dim LastRow As Long, LastCol As Integer

With Sheet1

LastRow = .UsedRange.Rows.Count

LastCol = .UsedRange.Columns.Count

.Range(.Cells(2, 1), .Cells(LastRow, LastCol)).Copy Destination:=Sheet2.Cells(1, 1) '假設復制到 Sheet2 的 A1 單元格

Application.CutCopyMode = False

End With

End Sub