Migrating from Excel 2007 to 2013 - odd behaviour for hide / reveal sheet/s

jkharmer

Board Regular
Joined
Jul 7, 2008
Messages
77
Hi,

I am in the process of migrating an Excel spreadsheet from 2007 to 2013. I have had to do a lot of work on conditional formatting as it seems that Microsoft have changed how the conditional formatting engine works from 2007 to 2010 - 2016. Anyway, that is pretty much sorted, but I have noticed another strange bit of behaviour on what is a very simple macro. The idea behind the code below is to simply have a toggle box which then hides or unhides a sheet named "Velocity". This works perfectly.

Sub mac_Tests_Velocity()

' Hides and Unhides Velocity Tab
Application.ScreenUpdating = False
If Sheets("TESTS").Range("p12").Value = 2 Then Sheets("Velocity").Visible = True
If Sheets("TESTS").Range("p12").Value = 1 Then Sheets("Velocity").Visible = False

If Sheets("TESTS").Range("p12").Value = 1 Then Sheets("Report").Range("XNR_VELOCITY").EntireRow.Hidden = True
If Sheets("TESTS").Range("p12").Value = 2 Then Sheets("Report").Range("XNR_VELOCITY").EntireRow.Hidden = False
Application.DisplayAlerts = True

End Sub

The next bit of code should do the same sort of thing, but instead of hiding or unhiding a single sheet, it should do 3 sheets:

Sub mac_Tests_VOCs()

' Hides and Unhides VOCs Tabs
Application.ScreenUpdating = False
If Sheets("TESTS").Range("p48").Value = 2 Then Sheets("VOCs").Visible = True
If Sheets("TESTS").Range("p48").Value = 1 Then Sheets("VOCs").Visible = False
If Sheets("TESTS").Range("p48").Value = 2 Then Sheets("Selected VOCs").Visible = True
If Sheets("TESTS").Range("p48").Value = 1 Then Sheets("Selected VOCs").Visible = False
If Sheets("TESTS").Range("p48").Value = 2 Then Sheets("Charted VOCs").Visible = True
If Sheets("TESTS").Range("p48").Value = 1 Then Sheets("Charted VOCs").Visible = False

If Sheets("TESTS").Range("p48").Value = 1 Then Sheets("Report").Range("XNR_VOCS").EntireRow.Hidden = True
If Sheets("TESTS").Range("p48").Value = 2 Then Sheets("Report").Range("XNR_VOCS").EntireRow.Hidden = False
Application.ScreenUpdating = True

End Sub

All this worked fine in Excel 2007. However, when I run this second macro in Excel 2016 (and 2013), it unhides the 3 sheets, but then jumps to the sheet called "Selected VOCs" (the middle one of the 3). It should not do this, it should stay on the sheet from where the macro was run.

Can anyone shed some light on why this behaviour may be occurring? I have around 30 of these hide / unhide toggle boxes, and the odd behaviour is only occurring when trying to hide / unhide multiple tabs at one time. Interestingly, it only does the sheet jumping thing when unhiding the sheets, it does not jump when toggling back to hiding the sheets.

Thanks, J
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

Forum statistics

Threads
1,221,446
Messages
6,159,917
Members
451,603
Latest member
SWahl

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