cjkohler88
New Member
- Joined
- Jan 20, 2010
- Messages
- 6
I am having some trouble getting my VBA to work. I am trying to unprotect a worksheet, set a cell to lock, insert a formula if the cell ="us" and then reprotect the cell. if the cell is not equal to "US" than I want to clear the cell. I can get the code to unlock, set the protection or unprotect, and then relock using the following code.
Private Sub Worksheet_Change(ByVal Target As Range)
If [c4] = "US" Then
ActiveSheet.Unprotect ("eXpense")
[c7].Locked = True
ActiveSheet.Protect ("eXpense")
'Remove locked property if B3's value is anything else or is deleted.
Else
ActiveSheet.Unprotect ("eXpense")
[c7].Locked = False
'Optional, reprotect sheet
ActiveSheet.Protect ("eXpense")
End If
End Sub
how do i get it to either insert a function or clear the cell. I have tried a lot of variations and it get an error or a loop every time
Private Sub Worksheet_Change(ByVal Target As Range)
If [c4] = "US" Then
ActiveSheet.Unprotect ("eXpense")
[c7].Locked = True
ActiveSheet.Protect ("eXpense")
'Remove locked property if B3's value is anything else or is deleted.
Else
ActiveSheet.Unprotect ("eXpense")
[c7].Locked = False
'Optional, reprotect sheet
ActiveSheet.Protect ("eXpense")
End If
End Sub
how do i get it to either insert a function or clear the cell. I have tried a lot of variations and it get an error or a loop every time