arifpunekar
New Member
- Joined
- May 2, 2014
- Messages
- 32
hi I am using windows 7 64 bit and excel 2007, I have large amount of macro enabled workbook, i have one vba code for auto lock cell when data entry and save, but when i shared workbook vba code not working , so i want to auto lock cell when data entry and save the file only that cells are locked which have data other blank cell are not protected in shared workbook. my code is here,
sir so please send me answer as early as possible. thanks in advance.
Code:
Private Sub Workbook_beforesave(ByVal saveasui As Boolean, cancel As Boolean)
On Error Resume Next 'resume to next line if any error occurs
Dim cell As Range
With ActiveSheet
'frist of all unprotect the entire 'sheet and unlock all cells
.Unprotect Password:="arifpunekar"
.Cells.Locked = False
'now search for non blank cells
'and lock them and unlock blank cells
For Each cell In ActiveSheet.UsedRange
If cell.Value = "" Then
cell.Locked = False
Else
cell.Locked = True
End If
Next cell
.Protect Password:="arifpunekar"
'protect with blank password.you can change it
End With
Exit Sub
End Sub
sir so please send me answer as early as possible. thanks in advance.
Last edited by a moderator: