macro fails when i have sheet protection on!!!

j4ymf

Well-known Member
Joined
Apr 28, 2003
Messages
741
Office Version
  1. 365
Platform
  1. Windows
hello all

i have been designing a sheet, i have just about finished it so i thought i would protect the sheet so no one can mess up my formulas.

i have just 1 bit that fails when i have protection turned on, i need to run this macro.



Rich (BB code):
Sub Macro4()
'
' Macro4 Macro
' Macro recorded 05/10/2006 by me
'

'
    ActiveWindow.SmallScroll Down:=6
    Range("B202:F249").Select
    ActiveWindow.SmallScroll Down:=-27
    Selection.Sort Key1:=Range("E202"), Order1:=xlAscending, Header:=xlGuess _
        , OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
        DataOption1:=xlSortNormal    ActiveWindow.SmallScroll Down:=-15
    Range("B201").Select
End Sub

the bold bit is the bit that is highlighted

it works fine with out protection, i have unlocked the cells any ideas

thanks jason
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
You can Unprotect/Protect in your code. And noo need for all that selecting or screen navigation either:

<font face=Tahoma><SPAN style="color:#00007F">Sub</SPAN> Macro4()
    ActiveSheet.Unprotect "PasswordHere"
        Range("B202:F249").Sort Key1:=Range("E202"), Order1:=xlAscending, Header:=xlGuess _
            , OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
            DataOption1:=xlSortNormal
    ActiveSheet.Protect "PasswordHere"
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

HTH,

Smitty
 
Upvote 0
thankyou

you are the best

it worked fantastic
 
Upvote 0
hello all

im pulling my hair out i have been playing with this code all week at home on office 2003, sent it into work using office 97 and i get a debug error it just wont work!!!!

works fine at home but fails at work any ideas,

Code:
Sub Macro4()
    ActiveSheet.Unprotect "PasswordHere"
        Range("B202:F249").Sort Key1:=Range("E202"), Order1:=xlAscending, Header:=xlGuess _
            , OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
            DataOption1:=xlSortNormal
    ActiveSheet.Protect "PasswordHere"
End Sub

the bit it fails on or the bit that is highlighted is dataoption1


please cast some light on it
many thanks jason
 
Upvote 0
Jason

Just delete that bit, it's not supported in earlier versions of Excel VBA.
Code:
Sub Macro4()
    ActiveSheet.Unprotect "PasswordHere"
        Range("B202:F249").Sort Key1:=Range("E202"), Order1:=xlAscending, Header:=xlGuess _
            , OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom            
    ActiveSheet.Protect "PasswordHere"
End Sub
 
Upvote 0
thankyou i will try tomorrow

u r a star
 
Upvote 0

Forum statistics

Threads
1,214,823
Messages
6,121,780
Members
449,049
Latest member
greyangel23

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