大佬教程收集整理的这篇文章主要介绍了Excel 宏在删除行时陷入循环,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我遇到了一个问题,我的 vba 宏卡住了,excel 冻结了。我已经将它缩小到 do until 循环,但似乎无法通过它。我尝试添加强制等待时间,看看这是否有帮助,但无济于事。
宏的目的是删除特定标题下的所有行,直到只剩下值为 'Net Change' 的一行。因此,在下面的示例中,将仅保留标题和“净更改”行。一如既往地感谢任何帮助。
编辑 1:运行此宏时,工作表中的所有其他行都需要保持不变。我的思考过程是从数组中找到标题并删除它下面不需要的行并继续到下一个标题。我还需要查看其他包含信息的标题。
Sub delete_Rows_NotNetChange()
Dim deleteNotNetChange As Variant
Dim sr As Range
Dim fr As Range
With ActiveSheet
Set sr = ActiveSheet.Range("A:A")
Application.Screenupdating = false
deleteNotNetChange = Array("4008 - Tenant PaID Trash Fee","4015 - Guardian Water (MulBerry)","6003 - Leasing Fee (3rd Party)",_
"6277 - Property Cleaning","6403 - Water","6408 - Trash and Recycling","6515 - Parking Garage","6612 - Property Manager Salary",_
"6622 - Workman's Comp Insurance","6633 - Coffee bar / Machine SupplIEs","6639 - Telephone service")
For Each header In deleteNotNetChange
On Error Resume Next
Range(Cells.Find(header).Address).SELEct
ActiveCell.offset(1,0).SELEct
Do Until instr(1,ActiveCell.Value,"Net Change") > 0
On Error Resume Next
ActiveCell.EntireRow.delete
Loop
Next header
Application.Screenupdating = True
End With
End Sub
是否有锁定的单元格?全部注释掉
On Error Resume Next
行并查看是否有任何错误抛出。
,if let Animal::Cat { weight,.. } = a {
println!("Your cat weights {} kg.",weight);
} else {
println!("get a cat");
};
壮举。 Application.Match
Union
,
如果要删除行,通常向上扫描。 编辑:修改为仅删除选定的部分,而保留其他部分不变。
@H_607_50@Option Explicit
Sub delete_Rows_NotNetChange()
const cOL = "A"
Dim ws As Worksheet
Dim i As Long,iLastRow As Long,n As Long,bdelete As Boolean
Dim s As String,iNet As Long
Dim Dict As Object
Set Dict = CreateObject("ScripTing.Dictionary")
Dict.Add "4008 - Tenant Paid Trash Fee",1
Dict.Add "4015 - Guardian Water (Mulberry)",1
Dict.Add "6003 - Leasing Fee (3rd Party)",1
Dict.Add "6277 - Property Cleaning",1
Dict.Add "6403 - Water",1
Dict.Add "6408 - Trash and Recycling",1
Dict.Add "6515 - Parking Garage",1
Dict.Add "6612 - Property Manager Salary",1
Dict.Add "6622 - Workman's Comp Insurance",1
Dict.Add "6633 - Coffee Bar / Machine Supplies",1
Dict.Add "6639 - Telephone service",1
Set ws = ActiveSheet
iLastRow = ws.Cells(Rows.Count,COL).End(xlUp).Row
For i = iLastRow To 1 Step -1
s = Trim(ws.Cells(i,COL))
If instr(1,s,"Net Change") > 0 Then
iNet = i - 1
Elseif Dict.exists(s) And iNet > i Then
ws.Rows(iNet & ":" & i + 1).EntireRow.delete
n = n + iNet - i
End If
Next
MsgBox n & " rows deleted"
End Sub
以上是大佬教程为你收集整理的Excel 宏在删除行时陷入循环全部内容,希望文章能够帮你解决Excel 宏在删除行时陷入循环所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。