+ Reply to Thread
Results 1 to 19 of 19

VBA to create backup of user input on protected sheets

  1. #1
    Forum Contributor
    Join Date
    11-08-2017
    Location
    Murfreesboro, TN
    MS-Off Ver
    MS 365
    Posts
    168

    VBA to create backup of user input on protected sheets

    I have a master spreadsheet with several sheets that allow the user to input their own custom data and they can then save the master including their custom inputs.

    I have made some changes to the master that I want to now give to the users, but I don't want them to lose all of the custom things they input. The sheets are all protected, but the cells where the user can put their own data are not locked.

    I want to have a macro that will copy the unprotected cells in specific, named sheets, and copy them to a second workbook, with the same sheet names and save the new file with the current date at the end of the filename. I will ultimately want a second macro to then upload the backed-up data back into the new file that I send to them. (I'll create a separate post for that if I need help.)

    I have found code to do a few of these things, but don't know how to put them all together.

    Code to open the new file (Target backup file for copying into): this works great for opening the initial empty backup file
    Please Login or Register  to view this content.

    Then I have this, but don't know how to combine them to work together. I want to take out the specific path to open the backup and insert the above code to allow the user to go find the file and then it sets the wbTarget as the file that they opened.

    Please Login or Register  to view this content.
    I found this to save a file with the current date at the end, but I don't want to specify the path. I want it to go to the same folder where they originally chose the backup file to open:

    Please Login or Register  to view this content.

    Any help to piece this together is appreciated. I posted so much because I didn't want anyone to think that I haven't tried to look this up myself. I am just not good with code and need help.

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: VBA to create backup of user input on protected sheets

    Try:
    Please Login or Register  to view this content.
    Change "MyPassword" (in red) in the code to the password used to protect the "Company Info" sheet in the target workbook. Please note that the "-1" saves the file with the day before the current date. If you want the current date, delete the "-1" in the code.
    Last edited by Mumps1; 11-24-2018 at 12:05 PM.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Forum Contributor
    Join Date
    11-08-2017
    Location
    Murfreesboro, TN
    MS-Off Ver
    MS 365
    Posts
    168

    Re: VBA to create backup of user input on protected sheets

    This worked!

    Now, to expand on this, if I want to copy additional sheets, can I just copy this line and paste it underneath this line with the names and ranges of the other sheets? Or is there something more involved than that?

    Please Login or Register  to view this content.

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: VBA to create backup of user input on protected sheets

    What are the names of the other sheets? Is the range to be copied the same on all sheets?

  5. #5
    Forum Contributor
    Join Date
    11-08-2017
    Location
    Murfreesboro, TN
    MS-Off Ver
    MS 365
    Posts
    168

    Re: VBA to create backup of user input on protected sheets

    Quote Originally Posted by Mumps1 View Post
    What are the names of the other sheets? Is the range to be copied the same on all sheets?
    I have 7 other sheets, named as follows:
    Preferences-backup
    Main Ingredients List-backup
    Main Materials List-backup
    Batter-Icing Amts-backup
    Categories-backup
    Recipes-backup
    Tools-Inventory-backup

    There are multiple ranges on each sheet, and none of them are the same. (I know....I'm difficult )

  6. #6
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: VBA to create backup of user input on protected sheets

    It looks like the names you listed refer to workbooks not sheets. If this is correct, What are the names of the source sheets in each workbook and the corresponding ranges to be copied? Will these workbooks be chosen one at a time using the FileDialogFilePicker as in the macro I suggested?

  7. #7
    Forum Contributor
    Join Date
    11-08-2017
    Location
    Murfreesboro, TN
    MS-Off Ver
    MS 365
    Posts
    168

    Re: VBA to create backup of user input on protected sheets

    No, they are all sheets in the same workbook as the "Company Info" sheet. The sheet names are the same as the sheet names in the original Active Workbook, with "-backup" added to them. I did that so I could tell them apart in the code lines.

  8. #8
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: VBA to create backup of user input on protected sheets

    What are the ranges to be copied from each sheet?

  9. #9
    Forum Contributor
    Join Date
    11-08-2017
    Location
    Murfreesboro, TN
    MS-Off Ver
    MS 365
    Posts
    168

    Re: VBA to create backup of user input on protected sheets

    Basically, it is all of the unlocked cells on each sheet. Since it is quite a few ranges on each sheet, and they are all different, I will just give all of the different cells/ranges on the Company Info Sheet. I was hoping to be able to adapt the ranges for each sheet without bothering you for the specifics.

    On the original code that you provided, I had to remove the .unprotect/.protect line items for it to work. I don't need it to unlock since the only cells I will be copying will be unlocked already. I only protected the sheets to keep users from accidentally deleting formulas.

    Here are the ranges on the Company Info Sheet of the Active Workbook (They are merged cells in most cases):

    D8:K9
    D11:K11
    D12:F12
    H12
    J12:K12
    D12:K13
    D13:K15
    D16:F16
    H16
    J16:K16
    D19:F19
    D21:F21
    D23:H23
    D25:H25

  10. #10
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: VBA to create backup of user input on protected sheets

    In you original post you copied Range("A2:E5") of the Company Info Sheet and pasted to cell B3. Where do you want to paste the ranges you posted in Post #9?

  11. #11
    Forum Contributor
    Join Date
    11-08-2017
    Location
    Murfreesboro, TN
    MS-Off Ver
    MS 365
    Posts
    168

    Re: VBA to create backup of user input on protected sheets

    So sorry. I actually changed the range being copied and where I pasted it. I put in "D8:K8" and pasted to D8.

    Ideally, I would like to paste the items in the same cells they originally came from into the same spot in the wbTarget file. Does that make sense?

  12. #12
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: VBA to create backup of user input on protected sheets

    Try this macro:
    Please Login or Register  to view this content.
    Insert the ranges where indicated (in red) for the corresponding sheets (in blue). Use the exact same format that I used for the "Company Info" sheet. Make sure the sheet names in your workbooks match the names in this macro. Of particular importance is that there are no spaces on either side of the hyphens. You can change the names in the code or the names in your workbooks. It doesn't matter as long as they match exactly.

  13. #13
    Forum Contributor
    Join Date
    11-08-2017
    Location
    Murfreesboro, TN
    MS-Off Ver
    MS 365
    Posts
    168

    Re: VBA to create backup of user input on protected sheets

    I am going in and adding in 1 range from each sheet just to test, but let me make sure that I understand the names of the sheets as you listed them.

    Please Login or Register  to view this content.
    Are these the sheet names for the workbook being copied, or the Target workbook (being copied to)?

    The workbook sheets being copied FROM do not have "-backup" and the workbook being copied TO does.

  14. #14
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: VBA to create backup of user input on protected sheets

    Try this version. Again make sure the sheet names match including spaces.
    Please Login or Register  to view this content.

  15. #15
    Forum Contributor
    Join Date
    11-08-2017
    Location
    Murfreesboro, TN
    MS-Off Ver
    MS 365
    Posts
    168

    Re: VBA to create backup of user input on protected sheets

    I changed the names slightly to make sure they matched the spreadsheets and added a range for each sheet. Here's the code I just tried to run:

    Please Login or Register  to view this content.
    I received this error:
    Copy-Paste1.jpg

  16. #16
    Forum Contributor
    Join Date
    11-08-2017
    Location
    Murfreesboro, TN
    MS-Off Ver
    MS 365
    Posts
    168

    Re: VBA to create backup of user input on protected sheets

    Wait....I see the error. Let me try again!

  17. #17
    Forum Contributor
    Join Date
    11-08-2017
    Location
    Murfreesboro, TN
    MS-Off Ver
    MS 365
    Posts
    168

    Re: VBA to create backup of user input on protected sheets

    I really appreciate all of your help so far!

    I changed the names on the Target worksheet to be the same as the Original worksheet, just to simplify things (one of the names was too long to add "-backup")

    I added 1 range for each sheet just to test that each one would work.

    Please Login or Register  to view this content.
    I am still getting the following error:
    Copy-Paste2.jpg

  18. #18
    Forum Contributor
    Join Date
    11-08-2017
    Location
    Murfreesboro, TN
    MS-Off Ver
    MS 365
    Posts
    168

    Re: VBA to create backup of user input on protected sheets

    Well, I posted a long reply, but apparently it did not save it. I got it to work! Thank you so much for your help!

    Here's the final code:

    Please Login or Register  to view this content.

  19. #19
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: VBA to create backup of user input on protected sheets

    You are very welcome.

+ 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. Use VBA to create copies of hidden sheets based on user input with specific names
    By kcombs in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-06-2018, 01:09 PM
  2. create user input for private sub
    By ammartino44 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-07-2015, 01:56 AM
  3. Replies: 1
    Last Post: 02-09-2013, 08:42 AM
  4. [SOLVED] Refreshing/Recalculating Sheets based on user input or switching between sheets
    By SonOfOdin in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-24-2012, 09:48 PM
  5. Pause macro for user input then search for user's answer across multiple sheets
    By sassy2 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-04-2009, 03:55 AM
  6. How to create a User input dialog box?
    By gshock in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 11-14-2008, 01:21 PM
  7. [SOLVED] Backup:always create a backup file in the save options
    By Alek in forum Excel General
    Replies: 1
    Last Post: 01-07-2006, 09:25 PM

Tags for this Thread

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