Hello. To start I'm very new to using macros/vba. I created an excel sheet with locked and unlocked cells. I wanted to have a way to delete the contents of the unlocked cells so the user can start from scratch when the new year comes around. I got the code to delete all unlocked cells using this code in vba:
What I can't figure out is how to prevent the deletion of 2 rows that are unlocked, more specifically from H4 to H53 & S4 to S53. So all other unlocked cells should be deleted except those. Any ideas would be greatly appreciated. PS I got the above code online. Thks.
Code:
Sub SelectUnlockedCells()
Dim c As Range, r As Range
For Each c In ActiveSheet.UsedRange
If c.Locked = False Then
If r Is Nothing Then
Set r = c
Else
Set r = Union(r, c)
End If
End If
Next
If r Is Nothing Then Exit Sub
r.Select
r.ClearContents
End Sub
What I can't figure out is how to prevent the deletion of 2 rows that are unlocked, more specifically from H4 to H53 & S4 to S53. So all other unlocked cells should be deleted except those. Any ideas would be greatly appreciated. PS I got the above code online. Thks.
Last edited by a moderator: