Solved

Macro Error - Calling a macro to protect sheets

Posted on 2011-03-10
7
261 Views
Last Modified: 2012-05-11
Putting the finishing touches on a project. I built a macro that will unprotect the sheets, then clear the contents of different ranges, then protect the sheet again.

the unprotect and protect are previous marcro's.

I keep gettin an error when it calls to protect the sheet again. Can't figure out why?
thanks
expert.xls
0
Comment
Question by:bvanscoy678
  • 3
  • 2
  • 2
7 Comments
 
LVL 8

Expert Comment

by:ragnarok89
Comment Utility
Odd,

your macro works fine on my machine, XP SP# and Excel 2003.
0
 
LVL 8

Expert Comment

by:ragnarok89
Comment Utility
that's SP3, by the way
0
 

Author Comment

by:bvanscoy678
Comment Utility
The clear all marco worked?

the protect all and deprotect all work just fine.
It is the Clear all macro that I am having issues with.

thanks
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 6

Accepted Solution

by:
royhsiao earned 500 total points
Comment Utility
Try this

Sub clear_sheet()
'
' clear_sheet Macro
' This macro will clear all enteries so it is ready for a new pay period
'

Call DeProtectAll
    Range("A4:C4").Select
   Call DeProtectAll
    Sheets(Array("first day of pay period", "2nd day of pay period", _
        "3rd day of pay period", "4th day of pay period", "5th day of pay period")). _
        Select
    Sheets("first day of pay period").Activate
    Range("A4:C31").ClearContents

Range("D4:D31").ClearContents

Range("F4:F31").ClearContents

Range("B3:C3").ClearContents

Call ProtectAll
End Sub

Public Sub DeProtectAll()

Dim ws As Worksheet

For Each ws In ActiveWorkbook.Worksheets
ws.Unprotect Password:="678"
Next ws

End Sub

Public Sub ProtectAll()

Dim ws As Worksheet

For Each ws In ActiveWorkbook.Worksheets
ws.protect Password:="678"
Next ws

End Sub

Open in new window

0
 

Author Comment

by:bvanscoy678
Comment Utility
I installed the code and it only clears day1, not the other days.
so I am guessing it is not going into group mode.

I'll keep looking at it.

thanks
0
 
LVL 6

Expert Comment

by:royhsiao
Comment Utility
oh you could add the following and update the range clear contents    

Sheets("first day of pay period").Activate
    Range("A4:C31").ClearContents
Sheets("2nd day of pay period").Activate
   Range("A4:C31").ClearContents
Sheets("3rd day of pay period").Activate
   Range("A4:C31").ClearContents
Sheets("4th day of pay period").Activate
   Range("A4:C31").ClearContents
Sheets("5th day of pay period").Activate
   Range("A4:C31").ClearContents
0
 

Author Closing Comment

by:bvanscoy678
Comment Utility
yes, this worked perfect.

thanks for the time.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

The new Microsoft OS looks great, is easier than ever to upgrade to, it is even free.  So what's the catch?  If you don't change the privacy settings, Microsoft will, in accordance with the (EULA) you clicked okay to without reading, collect all the…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now