• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Delete Row in Protected Sheet

gordons

New Member
Hai all,

I need your help, i made a macro code for move data from 1 sheet to another (Cut-Paste) in the protected sheet. The problem is, when i protect the sheet, my macro code didn't work. Do you have any idea?

Here is the macro code

Code:
Sub Oki()
h = 2
For r = 3 To 100 Step 1
    If Cells(r, "T") > 0 And _
       WorksheetFunction.IsText(Cells(r, "T")) = False Then
        Sheets(2).Activate
        DesRow = Cells(Rows.Count, "B").End(xlUp).Row + h
        h = 1
        Sheets(1).Activate
        Cells(r, "T").EntireRow.Copy Sheets(2).Cells(DesRow, "A")
        Application.CutCopyMode = False
        Cells(r, "T").EntireRow.Delete
        r = r - 1
            End If
Next

   
End Sub
 
@gordons
in first code you must unprotect your sheet to be able to copy file then in end code protect again your file, i hope this can help.
 
Hai Echo, thanks for help.

I add this code, but still not work.

Do you know what wrong? Here is the file.

Code:
Sub Oki()
Sheet1.Unprotect Password:="Secret"
h = 2
For r = 3 To 100 Step 1
   If Cells(r, "T") > 0 And _
       WorksheetFunction.IsText(Cells(r, "T")) = FalseThen
        Sheets(2).Activate
        DesRow = Cells(Rows.Count, "B").End(xlUp).Row + h
        h = 1
        Sheets(1).Activate
        Cells(r, "T").EntireRow.Copy Sheets(2).Cells(DesRow, "A")
        Application.CutCopyMode = False
        Cells(r, "T").EntireRow.Delete
        r = r - 1
Sheet1.Protect Password:="Secret"
           EndIf
Next

   
EndSub
 

Attachments

  • Project_Example2.xlsm
    37.8 KB · Views: 2
Dear Echo,

There is error that sound Run Time Error '1004' : delete method of range class failed.

Do you know why?
 
i have test this file is no problem and no error, may be you must restart your excel and save the file on your computer.
 
Back
Top