+ Reply to Thread
Results 1 to 10 of 10

Help making recorded macro work on protected sheet

  1. #1
    Registered User
    Join Date
    12-13-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    6

    Help making recorded macro work on protected sheet

    Hi everyone, I'm working on a project at the moment which required a Macro to do the following:

    (The button to activate the macro is located on a sheet called "Output" but all of the work takes places on one called "Calculation Sheet")

    • Copy cell at "Calculation Sheet!AB503"
    • Paste into a cell lower down as a value (Z506)
    • Highlight Z506 and go into data>Text to columns
    • Separate the data based on where semi colons are located and put the separated data into different columns (starting at A507)
    • Delete contents of Z506
    • Copy entirety of Row 507
    • Paste (transpose) into AA511
    • Delete entirety of Row 507~

    • Copy cell at "Calculation Sheet!AB504"
    • Paste into a cell lower down as a value (Z506)
    • Highlight Z506 and go into data>Text to columns
    • Separate the data based on where semi colons are located and put the separated data into different columns (starting at A507)
    • Delete contents of Z506
    • Copy entirety of Row 507
    • Paste (transpose) into AB511
    • Delete entirety of Row 507


    • Go back to Cell A1 on Output Sheet


    I recorded a macro to do this (and have cleaned it up slightly by removing "scrolling" stuff. This is what's left:

    Please Login or Register  to view this content.
    This code works fine as long as the Calculation Sheet is unprotected but I would ideally like to protect that sheet before sending it round to my coworkers (while ensuring the macro still works). Is there any way to do this?

    Thank you in advance

    E
    Last edited by EmmaOD; 12-13-2013 at 08:35 AM.

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Help making recorded macro work on protected sheet

    At the top of your code, after the comments, enter the line:
    Please Login or Register  to view this content.
    At the end (just before End Sub), enter the line:
    Please Login or Register  to view this content.
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Registered User
    Join Date
    12-13-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Help making recorded macro work on protected sheet

    Hi Olly, thanks for the reply.

    Apologies, I should have made clearer that I don't want them to need to enter the password to unprotect the sheet if possible.

    When I added in the lines of code I was prompted for a password before the macro could be run.

  4. #4
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Help making recorded macro work on protected sheet

    Okay, so change those lines to:

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Change "foo" to your password, obviously.


    If you take this approach, you may want to password protect your VBA project, to prevent users finding the password in unprotected code.

  5. #5
    Registered User
    Join Date
    12-13-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Help making recorded macro work on protected sheet

    You can do that? :P

  6. #6
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Help making recorded macro work on protected sheet

    Of course!

    In the VBE (VB Editor window), click Tools > VBAProject properties. Choose the Protection tab, tick 'Lock project for viewing' then enter the password of your choice in both boxes. You'll now need to enter that password to access your VBA project, but macros will still run without needing to enter a password.

  7. #7
    Registered User
    Join Date
    12-13-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    6

    re: Help making recorded macro work on protected sheet

    Brilliant,

    Thanks for your help Olly

    Have a nice day!

  8. #8
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    re: Help making recorded macro work on protected sheet

    Quote Originally Posted by EmmaOD View Post
    Brilliant,

    Thanks for your help Olly

    Have a nice day!

    Glad it helped Thanks for the feedback, and the rep.

  9. #9
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    re: Help making recorded macro work on protected sheet

    Just a quick followup - your code could be more efficient. Try something like this:

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    11-24-2013
    Location
    florida
    MS-Off Ver
    Excel 2010 & 2013
    Posts
    29

    Re: Help making recorded macro work on protected sheet

    Oliy
    I also found your solution very helpful and will use it in my own projects as a basic way to protect certain contents of sheets while still letting them be updated by macros. Thanks!!

+ Reply to Thread

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??
    By savethisid in forum Excel General
    Replies: 1
    Last Post: 04-06-2012, 07:01 AM
  3. 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
  4. 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
  5. Replies: 2
    Last Post: 07-11-2006, 11:15 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