Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default protect check box and cells

I have the code below, which places the current date in the cell next to the
check box, if ticked and unticked. The next code I,ve tried but does not work
or gives a run time error.
Is there a way to after checking the box, protect both the cell and the
checkbox, and not any other cell?

date checkbox:

Sub Process_CheckBox()
Dim cBox As CheckBox
Dim LCol As Long
Dim LRow As Long
Dim Rng As Range
LName = Application.Caller
Set cBox = ActiveSheet.CheckBoxes(LName)
'Find row that checkbox resides in
LCol = cBox.TopLeftCell.Column
LRow = cBox.TopLeftCell.Row
Set Rng = ActiveSheet.Cells(LRow + 0, LCol + 1)
'Change date in cell to the right of CheckBox, if checkbox is checked
If cBox.Value 0 Then
Rng.Value = Date
Else
Rng.ClearContents
End If
End Sub

protection:

Private Sub worksheet_change(ByVal target As Range)

ActiveSheet. Unprotect
Selection.Offset(-1, 0).Locked = True
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True


End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default protect check box and cells

If you protect the checkbox, then you won't have a way to uncheck it. Is that
what you really want?

If yes, then drop the second procedure and try assigning this macro to each of
your checkboxes:

Option Explicit
Sub Process_CheckBox()

Dim cBox As CheckBox
Dim PWD As String

PWD = "hi"

Set cBox = ActiveSheet.CheckBoxes(Application.Caller)

ActiveSheet.Unprotect Password:=PWD
cBox.Enabled = False
With cBox.TopLeftCell.Offset(0, 1)
.NumberFormat = "mmmm dd, yyyy hh:mm:ss"
.Value = Now
.Locked = True
End With
ActiveSheet.Protect Password:=PWD

End Sub



wynand wrote:

I have the code below, which places the current date in the cell next to the
check box, if ticked and unticked. The next code I,ve tried but does not work
or gives a run time error.
Is there a way to after checking the box, protect both the cell and the
checkbox, and not any other cell?

date checkbox:

Sub Process_CheckBox()
Dim cBox As CheckBox
Dim LCol As Long
Dim LRow As Long
Dim Rng As Range
LName = Application.Caller
Set cBox = ActiveSheet.CheckBoxes(LName)
'Find row that checkbox resides in
LCol = cBox.TopLeftCell.Column
LRow = cBox.TopLeftCell.Row
Set Rng = ActiveSheet.Cells(LRow + 0, LCol + 1)
'Change date in cell to the right of CheckBox, if checkbox is checked
If cBox.Value 0 Then
Rng.Value = Date
Else
Rng.ClearContents
End If
End Sub

protection:

Private Sub worksheet_change(ByVal target As Range)

ActiveSheet. Unprotect
Selection.Offset(-1, 0).Locked = True
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True


End Sub


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default protect check box and cells

Dave,
thanks a mil, works perfect

"Dave Peterson" wrote:

If you protect the checkbox, then you won't have a way to uncheck it. Is that
what you really want?

If yes, then drop the second procedure and try assigning this macro to each of
your checkboxes:

Option Explicit
Sub Process_CheckBox()

Dim cBox As CheckBox
Dim PWD As String

PWD = "hi"

Set cBox = ActiveSheet.CheckBoxes(Application.Caller)

ActiveSheet.Unprotect Password:=PWD
cBox.Enabled = False
With cBox.TopLeftCell.Offset(0, 1)
.NumberFormat = "mmmm dd, yyyy hh:mm:ss"
.Value = Now
.Locked = True
End With
ActiveSheet.Protect Password:=PWD

End Sub



wynand wrote:

I have the code below, which places the current date in the cell next to the
check box, if ticked and unticked. The next code I,ve tried but does not work
or gives a run time error.
Is there a way to after checking the box, protect both the cell and the
checkbox, and not any other cell?

date checkbox:

Sub Process_CheckBox()
Dim cBox As CheckBox
Dim LCol As Long
Dim LRow As Long
Dim Rng As Range
LName = Application.Caller
Set cBox = ActiveSheet.CheckBoxes(LName)
'Find row that checkbox resides in
LCol = cBox.TopLeftCell.Column
LRow = cBox.TopLeftCell.Row
Set Rng = ActiveSheet.Cells(LRow + 0, LCol + 1)
'Change date in cell to the right of CheckBox, if checkbox is checked
If cBox.Value 0 Then
Rng.Value = Date
Else
Rng.ClearContents
End If
End Sub

protection:

Private Sub worksheet_change(ByVal target As Range)

ActiveSheet. Unprotect
Selection.Offset(-1, 0).Locked = True
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True


End Sub


--

Dave Peterson
.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
protect worksheet with check box Wanna Learn Excel Discussion (Misc queries) 1 February 8th 09 06:38 PM
protect worksheet with check box Wanna Learn Excel Discussion (Misc queries) 0 February 8th 09 06:16 PM
Macro to allow spell check with protect sheet excel-chump[_2_] Excel Programming 6 October 22nd 07 01:53 PM
How can I protect a worksheet but still use ActiveX check-boxes? John Ewald Excel Discussion (Misc queries) 0 February 22nd 06 04:30 PM
Lock and protect cells without protect the sheet Christian[_7_] Excel Programming 6 December 28th 04 04:50 PM


All times are GMT +1. The time now is 04:53 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"