sheet protected > allow for macro to work

bluepenink

Well-known Member
Joined
Dec 21, 2010
Messages
585
hello

i have the following macro in a worksheet

Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
    Application.ScreenUpdating = False
    With ActiveSheet
        .AutoFilterMode = False
        .Range("myHeaders").AutoFilter
        If Range("myStoreNumber").Value <> 0 Then .Range("myHeaders").AutoFilter Field:=6, Criteria1:=Range("myStoreNumber").Value
    End With
    Application.ScreenUpdating = True
End Sub

i recently put a passowrd to protect all sheets, and basially, this macro is to filter the data in my table by store #....but after i put a password in..its not working

in VBA, i have the following code in "this workbook"..that i thought will enable the macro to work

Code:
Private Sub Workbook_Open()
For c = 1 To Sheets.Count
               With Worksheets(c)
        .Protect Password:="analyst", userinterfaceonly:=True
        .EnableOutlining = True
    End With
Next c
End Sub

can someone pls help!!
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
so does it become this now?

Code:
Private Sub Workbook_Open()
Sheets(c).Unprotect Password:="analyst"
For c = 1 To Sheets.Count
               With Worksheets(c)
        .Protect Password:="analyst", userinterfaceonly:=True, AllowFormattingCells:=True, Contents:=True, Scenarios:=True, _
            AllowFormattingColumns:=True, AllowFormattingRows:=True
        .EnableOutlining = True
    End With
Next c
End Sub

thx u?
 
Upvote 0
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
With ActiveSheet
.Unprotect Password:="analyst"
.AutoFilterMode = False
.Range("myHeaders").AutoFilter
If Range("myStoreNumber").Value <> 0 Then .Range("myHeaders").AutoFilter Field:=6, Criteria1:=Range("myStoreNumber").Value
.Protect Password:="analyst", userinterfaceonly:=True, AllowFormattingCells:=True, Contents:=True, Scenarios:=True, _
AllowFormattingColumns:=True, AllowFormattingRows:=True
End With
Application.ScreenUpdating = True
End Sub


The code should protect workbook just fine, i was guessing it was an issue with editing the workbook.
 
Upvote 0
sorry, disregard all that, I think what you are asking is this
Private Sub Workbook_Open()
For c = 1 To Sheets.Count
With Worksheets(c)
.Protect Password:="analyst", userinterfaceonly:=True, AllowFiltering:=True
.EnableOutlining = True
End With
Next c
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,297
Members
452,903
Latest member
Knuddeluff

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