Macro only fails when sheet is protected.

GrahamP

New Member
Joined
Jan 24, 2021
Messages
2
Office Version
  1. 2010
Platform
  1. Windows
Hi, I have copied some code into a macro which enables me to go to a selected sheet and defaults to the top of the page. This works perfectly until I protect the selected sheet. I need the worksheets to be protected for other users. Any suggestions?

TIA, Graham


Sub MainScreen()
ThisWorkbook.Sheets("Main Screen").Activate
Application.Goto Reference:=Range("a1"), Scroll:=True
End Sub
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Change the password (in red) to suit your needs:
Rich (BB code):
Sub MainScreen()
    With Sheets("Main Screen")
        .Unprotect Password:="MyPassword"
        Application.Goto Reference:=.Range("a1"), Scroll:=True
        .Protect Password:="MyPassword"
    End With
End Sub
 
Upvote 0
Thank you for the quick response, this worked for me but the only quirk was that one sheet (out of 4) did not go to the top. the issue seemed to be that it needed to view the first unlocked cell, and because my sheet did not have any unlocked cells visible at the top of the sheet, the view dropped below row 1. as soon as I unlocked a blank cell on row 1, row 1 became visible. this is more than acceptable for me, thank you again.
Cheers, Graham
 
Upvote 0

Forum statistics

Threads
1,215,020
Messages
6,122,709
Members
449,093
Latest member
Mnur

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