PDA

View Full Version : Solved: Checkbox madness



lacviet2005
05-19-2006, 02:39 PM
Dear all,
I have 2 identical spreadsheets (attached file). One with a lot of checkboxes (from control toolbox) for columns and rows and the other is where the value returns as ?1? if any checkboxes on Sheet1 are checked (exact same position). I can get it to work if writing vba code to every single checkbox. That?s painful. :banghead:
Is there a method to combine all the codes together?
Can somebody help me with this or point me to the right direction.

Thanks.

P.S. I'm very new with VBA, be gentle!:whistle:

XLGibbs
05-19-2006, 05:44 PM
Possibly, but perhaps there is a more efficient way to do what is needed...why do you need the second sheet, and what is the purpose of populating the corresponding cells with "1". It is likely you can achieve similar desired results using code and just the checkboxes...

lucas
05-19-2006, 08:15 PM
This might be easier....see attachment
ps. I only did the first one for you

lenze
05-20-2006, 09:45 AM
I hate working with check boxes so I avoid them whenever possible. Attached is a sample of what I often use in place of checkboxes. It is based on the Before_DoubleClick event. Maybe you will find this useful.

lenze

lacviet2005
05-21-2006, 03:11 PM
Thanks all for your replies. Awesome!!!

geekgirlau
05-22-2006, 02:23 AM
Do you want to mark this thread as "Solved"? If so, just go to "Thread Tools" at the top of the screen.

lacviet2005
05-22-2006, 10:10 AM
Hi Lenze,
I used your method....but this thing comes up "Run-time error '1004': Method 'Range' of object'_Worksheet' failed" and I hit debug button, it hightlights this line: "If Intersect(Target, Range("boxes")) Is Nothing Then"

Your codes:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Intersect(Target, Range("boxes")) Is Nothing Then Exit Sub
Target.Font.Name = "marlett"
If Target.Value <> "a" Then
Application.EnableEvents = False
Target.Value = "a"
Application.EnableEvents = True
Exit Sub
End If
If Target.Value = "a" Then
Application.EnableEvents = False
Target.Value = ""
Application.EnableEvents = True
Exit Sub
End If
End Sub

Everything works on your, but not mine. Please let me know what i have to do these codes.

Thanks and very much appreciate!

lenze
05-22-2006, 10:19 AM
Do you have a Named Range "boxes"??? Select ALL of the cells where you want a CheckBox (Use the CTRL Key to select non-contiguous cells). With them selected, choose Insert>Name>Define. Give them the name "boxes" (No quotes). The code should then run. If not, attach your sheet or a sample of what you've done.

lenze

BTW: The Application.Enable Event lines are not needed. They can ALL be removed.