A worksheet is unexpectedly activated

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
13,462
Office Version
  1. 2013
  2. 2010
Platform
  1. Windows
I have a macro assigned to a button that runs perfectly on the data in the active sheet and in other sheets as well using Excel 2010. However, when I try to run it using Excel 2013 or Excel 2016, a different sheet is unexpectedly activated so the macro generates an error. There is nothing in the code that activates this other sheet and, to be safe, the macro disables events, even though there is nothing in the event code that even references to this other sheet. I have tried assigning the active sheet name to a variable at the beginning of the macro and the using that variable to activate the sheet even though it is already the active sheet, but the other sheet is still activated. I was wondering if anyone else has experienced this problem. I was hoping to get some feedback on what could possibly cause this to happen. As I already mentioned, it runs without errors using Excel 2010. My suspicion is that there is a glitch in the 2013 and 2016 versions of Excel. I haven't posted the code because it is quite long and part of a large project that calculates the final results of a cross country meet. If anyone has any suggestions or would like the code to be posted, I can certainly do that. Many thanks in advance.

Also posted at: A worksheet is unexpectedly activated
 
@RoryA
Thank you for your suggestion. I had tried setting a worksheet variable to the activesheet at the start of the code, but unfortunately, the problem persisted. I agree that it's probably a bug. I'm exploring a way of modifying the code to see what else might work to perform the same tasks.

@Alex Blakenburg
That is correct, there is no line in the code that activates any other sheet. I'm trying to determine why this is happening so that it can be avoided.
 
Upvote 0

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Did you use it to reactivate the sheet after unprotecting? Most of your code uses unqualified range references which you should fix ideally
 
Upvote 0
Yes, I reactivated the sheet after unprotecting. When I tried setting a worksheet variable to the activesheet at the start of the code, I used the variable to qualify the range references using dot notation. It still didn't work.
 
Upvote 0
Curious. It worked fine for me in 2016 with those changes. If the ranges are properly qualified, I don’t see how it could fail.
 
Upvote 0
Could you post the changes that worked for you?
 
Upvote 0
I did the lazy way:

VBA Code:
Sub RaceResults()
    With Application
        .ScreenUpdating = False
        .Cursor = xlWait
        .EnableEvents = False
    End With

    Dim sourceSheet As Worksheet
    Set sourceSheet = ActiveSheet

    Sheets("FinalStandings").Unprotect Password:="iwbi48crci"
    Sheets("RegionQualifiers").Unprotect Password:="iwbi48crci"

    sourceSheet.Unprotect Password:="iwbi48crci"    
    sourceSheet.Activate
    Dim bottomC As Long
    'Deletes blank rows.
' rest of code
 
Upvote 0
Solution
The code works now without errors using Excel 2013. Thank you so much, Rory, for your expertise, time and patience. You have saved many people including myself, many headaches. :)
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,720
Members
448,986
Latest member
andreguerra

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top