简体   繁体   中英

Excel .delete & .clearcontents stop sub

I had a weird problem: lines like

rows("1:1000000").delete

and

rows("1:1000000").clearcontents

stop executed and exited the subs.
There was no error messages and error handling did not get any error number.
In debug mode the line got executed and then all and the next thing was just no macro running, exactly like the line meant "end sub".
I googled it, found nothing.
Tried this macro on other computer all to the same result.
There is no protected cells, no spreadsheet and workbook events.
Eventually i deleted all the modules in the files and all the subs in the same module and the code run through. Then closed the file without saving, re-opened it and everything worked fine.
My guess is there was something that switched back to normal somewhere in Excel guts.
Any idea what it could be? I am afraid the problem may come back sometime.

UPDATE: the problem reappeared again and disappeared after running another macro in another file

UPDATE2: full code of the sub is here:

Sub GenRep()
Application.EnableEvents = True
Sheets("rep").Activate
On Error Resume Next
Rows("3:1000000").Delete 'this line breaks execution, no further lines are executed, no error code nor warning messages
If Err.Number <> 0 Then Debug.Print "Err: " & Err.Number
NLines% = Sheets("db").Range("a1000000").End(xlUp).Row
Rows("2:" & NLines).FillDown
End Sub

I commented the line which breaks execution

Try:

Sheet1.Range(Rows(1), Rows(1000000)).EntireRow.Delete
Sheet1.Range(Rows(1), Rows(1000000)).ClearContents

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM