我是 VBA 新手,我知道必须有一种更简单、更有效的方法来编写此代码,但不熟悉正确的功能(例如如何在不粘贴现有数据的情况下粘贴到下一个工作表)。它适用于较小的工作表,但我必须在超过 60000 行的工作表上使用它。任何帮助将不胜感激。提前致谢。
Sub test()
Dim row As Long
With Excel.Application
.ScreenUpdating = False
.Calculation = Excel.xlCalculationManual
.EnableEvents = False
End With
For row = 1 To 65500
If ThisWorkbook.ActiveSheet.Cells(row, 14) <> "" Then
ThisWorkbook.ActiveSheet.Cells(row, 1).EntireRow.Copy
ThisWorkbook.ActiveSheet.Paste Destination:=ThisWorkbook.Sheets("SCO").Cells(row, 1)
ThisWorkbook.ActiveSheet.Cells(row + 1, 1).EntireRow.Copy
ThisWorkbook.ActiveSheet.Paste Destination:=ThisWorkbook.Sheets("SCO").Cells(row + 1, 1)
End If
Next
For row = 1 To 65500
If ThisWorkbook.Sheets("SCO").Cells(row, 14) = "" Then
ThisWorkbook.Sheets("SCO").Cells(row, 20).Value = 2
End If
Next
For x = 65500 To 1 Step -1
If ThisWorkbook.Sheets("SCO").Cells(x, 3) = "" Then
ThisWorkbook.Sheets("SCO").Cells(x, 1).EntireRow.Delete
End If
Next
For row = 1 To 65500
If ThisWorkbook.Sheets("SCO").Cells(row, 20) = 2 Then
ThisWorkbook.Sheets("SCO").Cells(row + 1, 1).EntireRow.Insert shift:=xlDown
End If
Next
With Excel.Application
.ScreenUpdating = True
.Calculation = Excel.xlAutomatic
.EnableEvents = True
End With
End Sub