Skip to content

Instantly share code, notes, and snippets.

@HeimMatthias
Created January 27, 2022 09:54
Show Gist options
  • Select an option

  • Save HeimMatthias/31eeaa2a14ba1c5495a96db7615b10e4 to your computer and use it in GitHub Desktop.

Select an option

Save HeimMatthias/31eeaa2a14ba1c5495a96db7615b10e4 to your computer and use it in GitHub Desktop.
This Excel-VBA script helps you to unlock individual cells that have already been unlocked using the 'editable ranges' method. Since Excel Online and the table versions of Excel do not support the latter method, this script will help you make your partially protected sheets functional on all platforms.
' UnlockEditableRanges: Hebt im aktiven Dokument auf allen Blättern den individuellen Sperrschutz der Zellen auf, die durch bearbeitbare Bereiche freigegeben wurden.
' Dadurch werden diese Bereiche auch auf Excel Online und auf Tablets beschreibbar, selbst wenn das Blatt geschützt ist.
' Achtung: bereits entsperrte Zellen werden durch das Skript nicht wieder geschützt, wenn sie sich nicht (mehr) in einem bearbeitbaren Bereich befinden.
Sub UnlockEditableRanges()
Dim Sheet As Excel.Worksheet
Dim EditableRange As Variant
Dim SheetIsProtected As Boolean
Dim cell As Excel.Range
For Each Sheet In ActiveWorkbook.Worksheets
Debug.Print "Zellschutz in Tabellenblatt " & Sheet.Name & " aufgrund von bearbeitbaren Bereichen setzen."
SheetIsProtected = Sheet.ProtectContents
Sheet.Protect 'Blattschutz ist notwendig, damit AllowEdit abgefragt werden kann
For Each EditableRange In Sheet.Protection.AllowEditRanges
Debug.Print "Bereich " & EditableRange.Title & "(" & EditableRange.Range.Address & ") wird entsperrt"
For Each cell In EditableRange.Range.Cells
If cell.AllowEdit Then
Sheet.Unprotect
If cell.MergeCells Then
Debug.Print "Verbundene Zellen " & cell.MergeArea.Address & " werden entsperrt"
cell.MergeArea.Locked = False
Else
cell.Locked = False
End If
Sheet.Protect
End If
Next
Next
If Not SheetIsProtected Then Sheet.Unprotect
Next
End Sub
@HeimMatthias
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment