简体   繁体   中英

Worksheet_Activate code fails to run in only 1 worksheet

I have a curious VBA problem. It has simple code to hide lines that aren't used. It has served me well, (I didn't actually make it) and all of the bugs fixed.

Now, however, it has stopped running the worksheet activate code in only one worksheet. The code for the other worksheets runs fine, and is nearly identical (list3 instead of list1 as a named range, and EntireColumn instead of EntireRow).

When I open Visual Basic and try to run the worksheet activate code manually, it gives me this error:

Compile error: Object library invalid or contains references to object definitions that could not be found.

I don't know where to start to try to fix it, especially when the Google seems to yield no results, even with the new condescending logo.

Private Sub Worksheet_Activate()

    Application.ScreenUpdating = False

    Dim cell As Range

    For Each cell In Range("list3") 'This changes to list1 to list4
        cell.EntireRow.Hidden = cell.Value2 = ""
    Next cell

    Application.ScreenUpdating = True

End Sub

Edit:

Two worksheets don't work now, I wonder if it has something to do with "EntireRow.Hidden" .

Not activate is the failure, but deactivate. Before activate excel must deactivate active sheet, so if there is only one sheet... can't be deactivated!

You can try a trick, minimize then maximize by activate. Is going to have the same effect, if you put them on the same statement you will not even feel the break.

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