+ Reply to Thread
Results 1 to 18 of 18

Copy and paste the data in excel ignoring Protected cells.

  1. #1
    Forum Contributor
    Join Date
    05-11-2013
    Location
    Mumbai
    MS-Off Ver
    Excel 2007 / 2010
    Posts
    270

    Copy and paste the data in excel ignoring Protected cells.

    Dear Friends,

    Please find the vba code below.
    Its does copy & paste special data related to another sheet in the sheet.

    The macro fails if there are protected cells in the sheet.

    Could you please assist me in solving the issue.

    Co
    Sub Break_Link_Col_ActiveNext()
    '
    ' Macro1 Macro
    '
    'Dim abc As Range
    ActiveWindow.ActivateNext
    Dim wb As Workbook
    Dim wb2 As Workbook
    Set wb = ThisWorkbook
    Dim cell As Range


    Set Rng = Application.InputBox( _
    Title:="Break_links", _
    Prompt:="Select a cell/range to break links", _
    Type:=8)
    If Rng Is Nothing Then
    MsgBox "please select range/cell"
    Else
    m = Rng.Address
    End If

    'Below code would do a for loop
    For Each cell In Range(m)
    If IsEmpty(cell) Then
    GoTo B
    Else
    abc = cell.Address
    If (InStr(1, Range(abc).Formula, "!", vbTextCompare)) > 0 Then
    Range(cell.Address).Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    End If
    End If
    B:
    Next cell

    Application.CutCopyMode = False

    MsgBox "Break link done"

    End Sub

  2. #2
    Valued Forum Contributor
    Join Date
    03-24-2020
    Location
    Thailand
    MS-Off Ver
    Office 2016
    Posts
    897

    Re: Copy and paste the data in excel ignoring Protected cells.

    When a cell property is set to be 'locked' the for this to apply, the sheet needs to be protected (with or without a password).
    If this is what you are referring to, the vba code could updated to unprotect the sheet, and protect again at the end.

    Please Login or Register  to view this content.
    If there is a password;
    Please Login or Register  to view this content.

    If we need to check if the sheet is protected, then the code will need a few more lines.
    If your Question is answered; please mark it SOLVED. If you are happy with a member's solution, say 'Thanks' and click the 'Star' to Add Reputation.

  3. #3
    Forum Contributor
    Join Date
    05-11-2013
    Location
    Mumbai
    MS-Off Ver
    Excel 2007 / 2010
    Posts
    270

    Re: Copy and paste the data in excel ignoring Protected cells.

    Sorry ORoos.

    This is not what I am looking for.

    There is a template file. Few cells are protected and few cells can be modified.
    In the modified cells I link the data of other files and other tabs.

    I need to paste special the data when I send the file to my boss.

    So the macro (attached above) does the work of paste specialing the cells.
    Macro fails only when there are protected cells.

    So I need help on macro which will ignore the protected cells and does paste special to unprotected cells. ( as defined in the above macro)

    Please assist.

  4. #4
    Valued Forum Contributor
    Join Date
    03-24-2020
    Location
    Thailand
    MS-Off Ver
    Office 2016
    Posts
    897

    Re: Copy and paste the data in excel ignoring Protected cells.

    If you simply want to skip protected cells when looping through your range, maybe adding the line below will work for you;

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    05-11-2013
    Location
    Mumbai
    MS-Off Ver
    Excel 2007 / 2010
    Posts
    270

    Re: Copy and paste the data in excel ignoring Protected cells.

    Thanks a lot.

    I am not too familiar with macros.

    Could you please add this code in my VBA code and do me a favour, please ?

  6. #6
    Valued Forum Contributor
    Join Date
    03-24-2020
    Location
    Thailand
    MS-Off Ver
    Office 2016
    Posts
    897

    Re: Copy and paste the data in excel ignoring Protected cells.

    Line inserted in your original code.
    Not tested: Make a copy/backup of your workbook for testing.



    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    05-11-2013
    Location
    Mumbai
    MS-Off Ver
    Excel 2007 / 2010
    Posts
    270

    Re: Copy and paste the data in excel ignoring Protected cells.

    Sorry ORoos.
    Its popping up debug error on line
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False

    Could you please assist ?

  8. #8
    Valued Forum Contributor
    Join Date
    03-24-2020
    Location
    Thailand
    MS-Off Ver
    Office 2016
    Posts
    897

    Re: Copy and paste the data in excel ignoring Protected cells.

    Without knowing how your worksheet is structured, I can't really know what the errors is.
    If you have a sample workbook (copy without sensitive information) please attach it so members can see what you are working with.

  9. #9
    Forum Contributor
    Join Date
    05-11-2013
    Location
    Mumbai
    MS-Off Ver
    Excel 2007 / 2010
    Posts
    270

    Re: Copy and paste the data in excel ignoring Protected cells.

    Dear ORoos,

    PFA the sample workbook for your reference.

    Please assist.
    Attached Files Attached Files

  10. #10
    Valued Forum Contributor
    Join Date
    03-24-2020
    Location
    Thailand
    MS-Off Ver
    Office 2016
    Posts
    897

    Re: Copy and paste the data in excel ignoring Protected cells.

    Sorry I have no idea what you try to do.

    What is the macro supposed to do?
    The macro is referring to 2 workbooks, is there another workbook in play.
    What data is coming from where?
    Which cells is what data to be entered?

    Maybe make a mock-up on what the result should be.

  11. #11
    Forum Contributor
    Join Date
    05-11-2013
    Location
    Mumbai
    MS-Off Ver
    Excel 2007 / 2010
    Posts
    270

    Re: Copy and paste the data in excel ignoring Protected cells.

    PFA the revised file.

    I have added the macro in the file.
    The macro will paste special the data when the cells are selected.

    When you run macro, select col. C.
    Macro runs fine.

    When you select col. C and D, the macro fails bcos col. D is protected.

    So please assist me in solving the debug error.
    Attached Files Attached Files

  12. #12
    Valued Forum Contributor
    Join Date
    03-24-2020
    Location
    Thailand
    MS-Off Ver
    Office 2016
    Posts
    897

    Re: Copy and paste the data in excel ignoring Protected cells.

    Have a look if the attached does what you need.
    Attached Files Attached Files

  13. #13
    Forum Contributor
    Join Date
    05-11-2013
    Location
    Mumbai
    MS-Off Ver
    Excel 2007 / 2010
    Posts
    270

    Re: Copy and paste the data in excel ignoring Protected cells.

    Sorry ORoos,

    The protected cell should be left as it is.
    In the file you sent, when we run macro, col. D does not remain protected.

    The macro should skip the protected cell and go to next cell and so on.

    The protected cells should remain as it is since its password protected by management.

    Please assist.

  14. #14
    Valued Forum Contributor
    Join Date
    03-24-2020
    Location
    Thailand
    MS-Off Ver
    Office 2016
    Posts
    897

    Re: Copy and paste the data in excel ignoring Protected cells.

    Ok. If cell is protected, skip it.

    Try the attached.
    Attached Files Attached Files

  15. #15
    Forum Contributor
    Join Date
    05-11-2013
    Location
    Mumbai
    MS-Off Ver
    Excel 2007 / 2010
    Posts
    270

    Re: Copy and paste the data in excel ignoring Protected cells.

    Thanks a ton, ORoos.

    You made my day.
    Its working fine.

  16. #16
    Forum Contributor
    Join Date
    05-11-2013
    Location
    Mumbai
    MS-Off Ver
    Excel 2007 / 2010
    Posts
    270

    Re: Copy and paste the data in excel ignoring Protected cells.

    Dear ORoos,
    I more favour.

    If I select multiple sheets and run the macro, its failing.
    Is there any way to run this macro on multiple sheet or whole workbook ?

    Please assist.
    Last edited by lalaarif1; 04-27-2022 at 02:07 AM. Reason: forgot to type the sentence

  17. #17
    Valued Forum Contributor
    Join Date
    03-24-2020
    Location
    Thailand
    MS-Off Ver
    Office 2016
    Posts
    897

    Re: Copy and paste the data in excel ignoring Protected cells.

    Macro 2 will allow you to select a range or ranges on another sheet.
    Attached Files Attached Files

  18. #18
    Forum Contributor
    Join Date
    05-11-2013
    Location
    Mumbai
    MS-Off Ver
    Excel 2007 / 2010
    Posts
    270

    Re: Copy and paste the data in excel ignoring Protected cells.

    Hi ORoos,

    The macro fails when I select multiple worksheets and run the macro.

    Could you please assist ?

+ 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. [SOLVED] How to copy and paste data if excel sheet is protected to select.
    By reimar_rem in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 04-09-2018, 08:24 AM
  2. Copy/Paste Protected Cells
    By erice in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-08-2017, 02:04 PM
  3. Replies: 12
    Last Post: 03-04-2015, 04:28 PM
  4. Replies: 1
    Last Post: 01-16-2013, 05:36 AM
  5. 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
  6. Copy and Paste Special Values Macro ignoring cells with specific condition
    By chendriks47 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-06-2011, 03:01 AM
  7. Copy and paste protected cells with formulas
    By aznprod517 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-19-2009, 02:13 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