View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Runtime error with vba and checkbox

It kind of sounds like you have a linkedcell for the checkbox in a locked cell
on that protected worksheet. Is that possible?

Remember the "lockedness" of a cell doesn't really do much until the worksheet
is protected.

This routine looks at the value of the checkbox (true = clicked) and does things
based on that.

I'm not sure if does what you really want, but it may be a start:

Option Explicit
Private Sub CheckBox1_Click()

Dim myRng As Range
Dim myPwd As String

myPwd = "secret"

Set myRng = Me.Range("C18, D19:D23, D25, D26:F26, J19:J23, P33, P35")

Me.Unprotect Password:=myPwd
myRng.Locked = Me.CheckBox1.Value
Me.CommandButton1.Visible = Not (Me.CheckBox1.Value)
Me.Protect Password:=myPwd

End Sub


I am guessing that all this stuff is on the Stats worksheet. I removed the
..select and the references to the worksheet name--I used Me. instead. Me.
refers to the thing holding the code--in this case the Stats worksheet.



SplatterKat wrote:

Heyas,

Hokay, noob behind the keyboard here and I have a situation I have no
clue on how to fix. I have only had minimal training in visual basic.
So any explanations in monosyllabic terms will be greatly appreciated.
Situation: I'm making a spreadsheet and want to limit access by users
to change data. I have a button that will generate data in the
necessary fields. I have an checkbox that when selected should disable
the commandbutton from functioning as well as locking the fields that
had information generated in them.
Here is the catch. When the sheet is unprotected the button and
checkbox do not lock the data fields or diable the command button, but
no error. But when I turn on the protection, I get an error '1004'
Unable to set the Locked property of the range class when I click on
the checkbox every time.

Here is the code:

Private Sub CheckBox1_Click()
' chkLockAttribs_Click()
ActiveWindow.ScrollRow = 8

Sheets("Stats").Range("C18").Select
If CheckBox1.Enabled = True Then
Sheets("Stats").Range("C18, D19:D23, D25, D26:F26, J19:J23,
P33, P35").Select
Selection.Locked = True
CommandButton1.Visible = False
Else
Sheets("Stats").Range("C18, D19:D23, D25, D26:F26, J19:J23,
P33, P35").Select
Selection.Locked = False
CommandButton1.Visible = True
End If

Sheets("Stats").Range("D19").Select
End Sub

Any help would be greatly appreciated. Thanks.

-SplatterKat-


--

Dave Peterson