ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Auditing Spreadsheet Protection (https://www.excelbanter.com/excel-discussion-misc-queries/247076-auditing-spreadsheet-protection.html)

Burningman

Auditing Spreadsheet Protection
 
Hi. Is there a way to highlight or otherwise quickly identify cells and/or
spreadsheets that are protected?
--
Burningman

Tom Hutchins

Auditing Spreadsheet Protection
 
Try this macro. It checks if the active sheet is protected. If it is, it
examines every cell in the UsedRange. Every cell that is locked is listed on
a new sheet which is added at the end of the workbook.

Option Explicit

Sub AuditShtProtection()
'Declare local variables.
Dim x As Long, c As Range, y As Long, z As Long
Dim StartSht As Worksheet, HitCount As Long
Dim NuSht As Worksheet
'Remember the starting sheet.
Set StartSht = ActiveSheet
If ActiveSheet.ProtectContents = True Then
'Add a new worksheet to the current workbook at the end.
Worksheets.Add.Move after:=Worksheets(Worksheets.Count)
Set NuSht = ActiveSheet
HitCount& = 1
DoEvents
StartSht.Activate
For Each c In ActiveSheet.UsedRange
If c.Locked = True Then
'List the cell's sheet name, address, and formula on NuSht.
HitCount& = HitCount& + 1
NuSht.Cells(HitCount&, 1).Value = "'" & ActiveSheet.Name
NuSht.Cells(HitCount&, 2).Value = "'" & c.Address
NuSht.Cells(HitCount&, 3).Value = "'" & c.Formula
End If
Next c
Else
MsgBox StartSht.Name & " is not protected", , "AuditShtProtection"
Exit Sub
End If
If HitCount& = 1 Then
MsgBox "No locked cells were found were found", , "AuditShtProtection"
Application.DisplayAlerts = False
NuSht.Delete
Application.DisplayAlerts = True
Else
'Add headings on NuSht
NuSht.Cells(1, 1).Value = "Sheet"
NuSht.Cells(1, 2).Value = "Cell"
NuSht.Cells(1, 3).Value = "Formula"
NuSht.Activate
NuSht.Cells.Select
NuSht.Cells.EntireColumn.AutoFit
End If
cleanup:
'Free object variables.
Set StartSht = Nothing
Set NuSht = Nothing
Set c = Nothing
MsgBox "Done!"
End Sub

Put the macro code in a general VBA module in your workbook (it doesn't have
to be the same workbook you want to audit). If you are new to macros, this
link to Jon Peltier's site may be helpful:
http://peltiertech.com/WordPress/200...e-elses-macro/

Hope this helps,

Hutch

"Burningman" wrote:

Hi. Is there a way to highlight or otherwise quickly identify cells and/or
spreadsheets that are protected?
--
Burningman



All times are GMT +1. The time now is 10:15 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com