none
Accountant RRS feed

Answers

  • Hi Hany,

    If all the worksheets are protected, you need to unprotect them instead of unprotect the first worksheet.

    Please modify the code like this:

    Sub clear()
      Dim a As Long
         For a = 1 To 240
            Worksheets(a).Unprotect Password:="p@$$w0rd"
    
             Worksheets(a).Range("a2,b9:d23,f9:q23,a27:q31").clearcontents
             Worksheets(a).Protect Password:="p@$$w0rd"
         Next a
     MsgBox "Clear Complete"
     
     End Sub

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, April 29, 2015 6:49 AM
    Moderator

All replies

  • I write this Code

    Sub clear()
    Worksheets(a).Unprotect Password:="p@$$w0rd"
    Dim a As Long
        For a = 1 To 240
            Worksheets(a).Range("a2,b9:d23,f9:q23,a27:q31").clearcontents
        Next a
    MsgBox "Clear Complete"
    Worksheets(a).Protect Password:="p@$$w0rd"
    End Sub

    but i have this message

    Compile Error :

    Duplicate declaration in current scope

    Tuesday, April 28, 2015 7:49 AM
  • Hi Hany,

    If all the worksheets are protected, you need to unprotect them instead of unprotect the first worksheet.

    Please modify the code like this:

    Sub clear()
      Dim a As Long
         For a = 1 To 240
            Worksheets(a).Unprotect Password:="p@$$w0rd"
    
             Worksheets(a).Range("a2,b9:d23,f9:q23,a27:q31").clearcontents
             Worksheets(a).Protect Password:="p@$$w0rd"
         Next a
     MsgBox "Clear Complete"
     
     End Sub

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, April 29, 2015 6:49 AM
    Moderator
  • its Working thank u too much Starain
    Wednesday, April 29, 2015 7:02 AM