我不确定我的代码有什么问题。我以为我设置了正确的范围,但也许不是。我确实尝试设置多个范围。错误出现在代码“Range("CL_Paid").Paste”的最后一行
Sub test()
Dim HR_Paid, HR_Unpaid, E_Paid, E_Unpaid, SE_Paid, SE_Unpaid, CL_Paid, CL_Unpaid As Range
Set HR_Paid = Sheets("Data").Range("A1:L49")
Set HR_Unpaid = Sheets("Data").Range("A50:L99")
Set E_Paid = Sheets("Data").Range("A100:L149")
Set E_Unpaid = Sheets("Data").Range("A150:L199")
Set SE_Paid = Sheets("Data").Range("A200:L249")
Set SE_Unpaid = Sheets("Data").Range("A250:L299")
Set CL_Paid = Sheets("Data").Range("A300:L349")
Set CL_Unpaid = Sheets("Data").Range("A350:L399")
With Sheets("Data")
.Select
ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView
.DisplayPageBreaks = False
Firstrow = .UsedRange.Cells(1).Row
Lastrow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
For Lrow = Lastrow To Firstrow Step -1
With .Cells(Lrow, "D")
If Not IsError(.Value) Then
If .Value = ("CL") Then .EntireRow.Cut
Range("CL_Paid").Paste
End If
End With
Next Lrow
End With
End Sub