macro fails when i have sheet protection on!!!

j4ymf

Well-known Member
Joined
Apr 28, 2003
Messages
653
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

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Smitty

Legend
Joined
May 15, 2003
Messages
29,536
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
 

j4ymf

Well-known Member
Joined
Apr 28, 2003
Messages
653
Office Version
  1. 365
Platform
  1. Windows
thankyou

you are the best

it worked fantastic
 

j4ymf

Well-known Member
Joined
Apr 28, 2003
Messages
653
Office Version
  1. 365
Platform
  1. Windows
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
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,304
Office Version
  1. 365
Platform
  1. Windows
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
 

j4ymf

Well-known Member
Joined
Apr 28, 2003
Messages
653
Office Version
  1. 365
Platform
  1. Windows
thankyou i will try tomorrow

u r a star
 

Forum statistics

Threads
1,141,629
Messages
5,707,506
Members
421,511
Latest member
mgroah1

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
Top