VBA中的429错误。自动行删除宏

时间:2018-08-13 19:24:19

标签: excel vba activex

最近工作了几周后,我的宏崩溃了。我打开Excel以显示“自动化错误灾难性失败”消息。经过一些研究之后,我发现一些信息表明要删除C:\ users [USER] \ appdata中的一些Temp .exd文件。这实际上使我调试了代码,但是现在我在代码中遇到429错误上周工作。上周,我确实在工作表中添加了引用下面的宏的按钮(ActiveX按钮),但即使在通过电子邮件发送给同事之后也可以使用。我很困惑,无法找到答案。同样,此代码是我进行编码的第一个真正的尝试,因此欢迎任何信息!

Dim workrange As Range
Dim Firstrow As Integer
Dim Lastrow As Integer
Dim lrow As Integer
Dim arr As String


'Find first and last used row in column S "Observation"
'This macro must be done each time you add new data
Set sht = ThisWorkbook.Sheets("obs")
noObser = sht.ListObjects("noneed").DataBodyRange


Range("S:S").Select
Firstrow = ActiveSheet.UsedRange.Cells(2).Row
Lastrow = ActiveSheet.Range("M1").Offset(Raw.Rows.Count - 1, 0).End(xlUp).Row


'Loop through used cells backwards and delete if needed
For lrow = Lastrow To Firstrow + 1 Step -1
    Set workrange = Cells(lrow, 19)
    If Not IsError(Application.Match(workrange.Value, noObser, 0)) Then workrange.EntireRow.Delete

Next lrow

MsgBox "Extra Activity Removed"

End Sub

代码的V2

Sub RemoveNoActivity()

Dim workrange As Range
Dim Firstrow As Integer
Dim Lastrow As Integer
Dim lrow As Integer
Dim sht As Worksheet
Dim noObser As ListRows

'Find first and last used row in column S "Observation"
'This macro must be done each time you add new data
Set sht = ThisWorkbook.Sheets("Obs")
Set noObser = sht.ListObjects("noneed").DataBodyRange

Range("S:S").Select
Firstrow = ActiveSheet.UsedRange.Cells(2).Row
Lastrow = ActiveSheet.Range("S1").End(xlUp).Row


'Loop through used cells backwards and delete if needed
For lrow = Lastrow To Firstrow + 1 Step -1
    Set workrange = Cells(lrow, 19)
    If Not IsError(Application.Match(workrange.Value, noObser, 0)) Then workrange.EntireRow.Delete

Next lrow

MsgBox "Extra Activity Removed"

End Sub

这是我的位置,这要归功于BigBen,但在set上仍然出现429错误


事实证明,代码很好,并且我创建了许多干扰我的对象调用的Excel对象。经过更多搜索之后,最好的解决方案是将工作表复制并粘贴到新的工作簿中并导出模块。 Image of the XL logo excel sheets i cannot delete

0 个答案:

没有答案