+ Reply to Thread
Results 1 to 11 of 11

Copy/paste/cut/insert rows across protected/locked columns

  1. #1
    Registered User
    Join Date
    10-20-2015
    Location
    Mexico City, Mexico
    MS-Off Ver
    2010
    Posts
    12

    Copy/paste/cut/insert rows across protected/locked columns

    Hi guys,

    I'm having a lot of trouble finding a solution to this issue, so I hope you can help me.

    Two columns in my sheet have formulas that I do not want users to edit, including the values created by those formulas. However, users want to be able to copy, paste, cut, and insert ROWS from one place to another anywhere in the sheet.

    For example, row 2 needs to be pasted into row 3, but columns P and W are locked for editing, so excel throws an error.

    If there is a macro or VBA code I can add to the sheet to achieve this I would be very grateful to know what it is. None of the code I've tried so far has helped. My current workbook is attached and locked with no password.


    MBP - Statistics.xlsm

  2. #2
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    365 Version 2409
    Posts
    2,789

    Re: Copy/paste/cut/insert rows across protected/locked columns

    How about using an application.inputbox set to accept a range.
    Set your protection to allow a user to select locked cells.
    When the macro runs it can prompt them to type or choose the range they want to copy and then type or choose the range to paste it into, it then unlocks the sheet, pastes the code and relocks the sheet, this happens in a fraction of a second.

    You can restrict the range they can select, copy from and copy to with the code, using the intersect method.

    Application.inputbox, you are interested in type 8 with which you can either type in a range or select the range.
    Last edited by skywriter; 10-21-2015 at 09:43 PM.

  3. #3
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Copy/paste/cut/insert rows across protected/locked columns

    Instead of password protecting the two columns, you could have a Worksheet_Change event procedure to re-apply the formulas to columns Q and W if they are changed.

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  4. #4
    Registered User
    Join Date
    10-20-2015
    Location
    Mexico City, Mexico
    MS-Off Ver
    2010
    Posts
    12

    Question Re: Copy/paste/cut/insert rows across protected/locked columns

    Quote Originally Posted by AlphaFrog View Post
    Instead of password protecting the two columns, you could have a Worksheet_Change event procedure to re-apply the formulas to columns Q and W if they are changed.
    While this solution is not 100% ideal (the user could get stuck in an incorrect formula loop if they accidentally edit it), it certainly achieves the function I was looking for.

    Thank you very much; you are indeed the alpha frog.

  5. #5
    Registered User
    Join Date
    10-20-2015
    Location
    Mexico City, Mexico
    MS-Off Ver
    2010
    Posts
    12

    Re: Copy/paste/cut/insert rows across protected/locked columns

    How about using an application.inputbox set to accept a range.
    Set your protection to allow a user to select locked cells.
    When the macro runs it can prompt them to type or choose the range they want to copy and then type or choose the range to paste it into, it then unlocks the sheet, pastes the code and relocks the sheet, this happens in a fraction of a second.

    You can restrict the range they can select, copy from and copy to with the code, using the intersect method.

    Application.inputbox, you are interested in type 8 with which you can either type in a range or select the range.
    Thanks for your reply. Would this solution retain the functionality of copy/paste without additional steps? I don't think users would find it easy to input cell ranges instead of the usual right-click route.

  6. #6
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    365 Version 2409
    Posts
    2,789

    Re: Copy/paste/cut/insert rows across protected/locked columns

    With a type 8 application input box they can drag their mouse across what they want to select or click a row or column, isn't that the least one usually has to do to copy something?

    Here I have simply selected a range with my mouse and you see the results.

    Range.jpg

  7. #7
    Registered User
    Join Date
    10-20-2015
    Location
    Mexico City, Mexico
    MS-Off Ver
    2010
    Posts
    12

    Re: Copy/paste/cut/insert rows across protected/locked columns

    Quote Originally Posted by AlphaFrog View Post
    Instead of password protecting the two columns, you could have a Worksheet_Change event procedure to re-apply the formulas to columns Q and W if they are changed.

    Please Login or Register  to view this content.
    This worked perfectly until two new sheets were added to the workbook and the original was renamed. Additionally, I added some new columns and moved others, resulting in the original columns Q & W becoming R & X.

    To get around the difference in columns, I modified the code somewhat, but the functionality has completely stopped working. Here's my modification:
    Please Login or Register  to view this content.
    Please could you let me know what can be done to rectify it, and perhaps how I could change it again if the decision is made to add more columns/sheets. Thank you very much.

  8. #8
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Copy/paste/cut/insert rows across protected/locked columns

    Try saving and closing the workbook. Then restart Excel and try it again.

    I suspect you edited the original code and had an error. Then you fixed the error. That's when the code stopped working. That's because this line Application.EnableEvents = False suspends the code from triggering so the next line can change the worksheet and not trigger the code again.

    If you restart Excel, that should fix it.

    Before you save, add these lines. That will prevent it from having this problem again

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    10-20-2015
    Location
    Mexico City, Mexico
    MS-Off Ver
    2010
    Posts
    12

    Re: Copy/paste/cut/insert rows across protected/locked columns

    Quote Originally Posted by AlphaFrog View Post
    Try saving and closing the workbook. Then restart Excel and try it again.

    I suspect you edited the original code and had an error. Then you fixed the error. That's when the code stopped working. That's because this line Application.EnableEvents = False suspends the code from triggering so the next line can change the worksheet and not trigger the code again.

    If you restart Excel, that should fix it.

    Before you save, add these lines. That will prevent it from having this problem again

    Please Login or Register  to view this content.
    The functionality now works again (thank you) but I'm struggling to get column X to generate the correct data.

    While the restart and the addition of this code has helped with column R (with the formula now drawing data from columns N & Q), column X is having issues. X should have this formula: =IF(OR(V2>TODAY(),AND(W2="",V2="")),"",IF(W2="",DATEDIF(V2,TODAY(),"d"),W2-V2))

    But instead shows this one: =IF(OR(T2>TODAY(),AND(W2="",T2="")),"",IF(W2="",DATEDIF(T2,TODAY(),"d"),W2-T2))

    Also, how would I write the above code if I need to have the same functionality on another sheet? I'm guessing it has something to do with "FormulaR1C1 = _" clause, but I don't know how to amend that for various columns (it took some codebreaking to understand that [-4] and [-1] was the way to fix column R, but now I stumped).

    Excuse my ignorance, but I'm an relative Excel noob compared to most folks in here.

  10. #10
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Copy/paste/cut/insert rows across protected/locked columns

    This uses two different formulas for R and X

    Please Login or Register  to view this content.

    R1C1 References

  11. #11
    Registered User
    Join Date
    10-20-2015
    Location
    Mexico City, Mexico
    MS-Off Ver
    2010
    Posts
    12

    Re: Copy/paste/cut/insert rows across protected/locked columns

    Quote Originally Posted by AlphaFrog View Post
    This uses two different formulas for R and X

    Please Login or Register  to view this content.

    R1C1 References
    SO awesome, thanks. I can now use the single R1C1 refs for other sheets. You're a godsend. Thank you. I'll study up on the reference systems.

+ 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. Insert Rows When Columns are Locked and Sheet Protected
    By HangMan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-22-2015, 11:30 AM
  2. Replies: 3
    Last Post: 07-26-2014, 06:12 AM
  3. Replies: 1
    Last Post: 03-29-2014, 09:56 AM
  4. Copy and paste insert rows with protected cells in protected worksheet
    By excel_gecko in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-24-2012, 05:50 PM
  5. [SOLVED] Code to cut and paste rows (insert cut cells) in a protected Excel sheet
    By bob.mc in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-27-2012, 04:47 PM
  6. How to allow user paste(Ctrl + V) a row to protected sheet(some columns are locked)
    By openSuSe in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-30-2008, 07:35 AM
  7. [SOLVED] my sheet is locked and protected, i want to insert row with autofo
    By yogesh in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-17-2006, 10:45 AM

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