Results 1 to 5 of 5

Macro does not work with protected sheet

Threaded View

  1. #4
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565

    Re: Macro does not work with protected sheet

    Thanks a lot for your help for sorting the code for me! Massive help!
    You're welcome. Always happy to try and help a fellow Aussie and thanks for rep

    This line of code...

    For Each ws In Worksheets
    ...loops through all the sheets in workbook.

    This line of code...

    If ws.CodeName <> "Sheet2" Then 'References the code name of the tab.
    ...tells the code to ignore the code name of "Sheet2" as this tab is where the results are consolidated so it makes sense not to filter and copy its data. The code name of a sheet is found in the left-hand panel of the Visual Basic Editor (where the macros are housed). In your workbook's VBE you will see Sheet2 (Disposed) where Sheet2 is the code name and Disposed is the actual tab name you see from Excel's front end. The benefit of referencing sheets via their code name is that the tab name can change but the underlying code will still work. You can also change the code name of the tab if you wish via the VBE.

    This line of code...

    ws.Protect Password:=123, DrawingObjects:=True, Contents:=True
    ...sets the level of protection for the sheet. You see these options from the Protect Sheet dialog i.e. when you manually protect a sheet via the Protect Sheet option of the Protect tab from the Review ribbon. These are the default selections.

    Hope that helps.

    Robert
    Last edited by Trebor76; 07-24-2021 at 11:48 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. MAcro does not work when certain cells in a work sheet are protected
    By Unnati in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-10-2012, 03:38 AM
  2. Macro does not work when sheet is protected?? Please Help
    By savethisid in forum Excel General
    Replies: 1
    Last Post: 04-06-2012, 07:24 AM
  3. Macro does not work when sheet is protected??
    By savethisid in forum Excel General
    Replies: 1
    Last Post: 04-06-2012, 07:01 AM
  4. protected sheet, allow for macro to work
    By jw01 in forum Excel General
    Replies: 2
    Last Post: 08-22-2011, 02:55 PM
  5. Getting a Macro to work on protected sheet
    By Benw in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-26-2010, 06:33 AM
  6. Macro will not work when sheet is Protected
    By alachape in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-02-2008, 03:13 PM
  7. Replies: 2
    Last Post: 07-11-2006, 11:15 PM
  8. Macro protected work sheet
    By Henry in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-14-2006, 07:40 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1