Vba 编译错误“;以“结束”;
对于下面的代码,我不断得到编译错误:“EndWith” 我不理解错误消息,因为每个Vba 编译错误“;以“结束”;,vba,excel,Vba,Excel,对于下面的代码,我不断得到编译错误:“EndWith” 我不理解错误消息,因为每个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
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
与ActiveWorkbook.worksheet(“MIM数据”)
昏暗的德拉夫提斯
对于DelAftDis=单元格(Rows.Count,10)。结束(xlUp)。行到2步骤-1
带单元格(DelAftDis,10)
如果.Value=“SBU争议后”则
行(DelAftDis).EntireRow.Delete
以“结束代码行似乎缺少“如果结束”:
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
您缺少此IF的结束IFIF.Value=“SBU争议后”然后@ScottCraner Ok。谢谢成功了。但是为什么VBA告诉我这是with
语句的问题?它在IF语句中看到那些以结尾的,所以在查找时,它无法找到之前的with语句的结尾,这是第一个错误。如果您没有使用With Blocks,它会正确地找到丢失的端,如果。@ScottCraner有意义的话。谢谢你的解释。你应该把这个作为一个答案,让别人看到。肯定会有助于将来的参考。
With Cells(DelAftDis, 10)
If .Value = "After Dispute For SBU" Then
Rows(DelAftDis).EntireRow.Delete
End if
End With