对于下面的代码,我不断收到编译错误:“没有使用结束”
Sub Copy_Swivel_To_MIM_DATA()
Application.ScreenUpdating = False
With ActiveWorkbook.Worksheets("Swivel")
.Columns("AC:AC").EntireColumn.Copy Destination:=Sheets("MIM Data").Range("A1")
.Columns("J:J").EntireColumn.Copy Destination:=Sheets("MIM Data").Range("B1")
.Columns("K:K").EntireColumn.Copy Destination:=Sheets("MIM Data").Range("C1")
.Columns("L:L").EntireColumn.Copy Destination:=Sheets("MIM Data").Range("D1")
.Columns("M:M").EntireColumn.Copy Destination:=Sheets("MIM Data").Range("E1")
.Columns("N:N").EntireColumn.Copy Destination:=Sheets("MIM Data").Range("F1")
.Columns("O:O").EntireColumn.Copy Destination:=Sheets("MIM Data").Range("G1")
.Columns("P:P").EntireColumn.Copy Destination:=Sheets("MIM Data").Range("H1")
.Columns("Q:Q").EntireColumn.Copy Destination:=Sheets("MIM Data").Range("I1")
.Columns("F:F").EntireColumn.Copy Destination:=Sheets("MIM Data").Range("J1")
End With
With ActiveWorkbook.Worksheets("MIM Data")
.Columns("A:J").EntireColumn.Hidden = False
End With
With ActiveWorkbook.Worksheets("MIM Data").Sort
With .SortFields
.Clear
.Add Key:=Range("A2:A2000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.Add Key:=Range("G2:G2000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.Add Key:=Range("B2:B2000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.Add Key:=Range("C2:C2000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.Add Key:=Range("D2:D2000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.Add Key:=Range("E2:E2000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
End With
.SetRange Range("A2:AE2000")
.Apply
End With
Worksheets("MIM QA").Columns("A:J").AutoFit
With Sheets("MIM Data").Range("A2:AA2000")
With .Font
.name = "Arial"
.FontStyle = "Regular"
.Size = 10
.Color = RGB(0, 0, 255)
End With
End With
With ActiveWorkbook.Worksheets("MIM Data")
Dim DelAftDis As Long
For DelAftDis = Cells(Rows.Count, 10).End(xlUp).row To 2 Step -1
With Cells(DelAftDis, 10)
If .Value = "After Dispute For SBU" Then
Rows(DelAftDis).EntireRow.Delete
End With
Next DelAftDis
End With
Application.ScreenUpdating = True
Range("A" & Rows.Count).End(xlUp).Offset(1).Select
End Sub
我不理解错误消息,因为每个With
都有关联的End With
。表示为问题的行是:
With ActiveWorkbook.Worksheets("MIM Data")
Dim DelAftDis As Long
For DelAftDis = Cells(Rows.Count, 10).End(xlUp).row To 2 Step -1
With Cells(DelAftDis, 10)
If .Value = "After Dispute For SBU" Then
Rows(DelAftDis).EntireRow.Delete
End With ' <--- This is highlighted by the debugger
Next DelAftDis
End With
我错过了With
还是End With
?如果是的话,应该放在哪里?
答案 0 :(得分:2)
您似乎缺少代码行的“End if”:
If .Value = "After Dispute For SBU" Then
只需在结尾添加“End if”,如下所示:
With Cells(DelAftDis, 10)
If .Value = "After Dispute For SBU" Then
Rows(DelAftDis).EntireRow.Delete
End if
End With