View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
GS[_2_] GS[_2_] is offline
external usenet poster
 
Posts: 3,514
Default Change states of some checkboxes from drop-down list?

TheMilkGuy presented the following explanation :
Hi folks, long time lurker here using Excel 2010...

I have a drop-down list in cell H8 that contains 4 values (A thru D). Their
TRUE/FALSE results are stored in unlocked cells on another protected sheet in
the workbook.


If these are 'linked' to your Forms controls then just change their
values to whatever you want the control to display. (See sample below)

If A or B are selected, I'd like for Check Box 96 and 97 (on the original
page) to check automatically, but still be de-selectable if required.

If C or D are selected, I'd like for 96 and 97 to uncheck automatically, but
still be selectable if required.

I've toyed around with VB code but TBH I don't know what I'm doing.
Admission is the first step, right? haha

Many thanks,
Craig


This code goes in the code module for the sheet containing the check
boxes you want to toggle. (Right-click the sheet tab and select 'View
code')

I put 4 ActiveX checkboxes (1:4) and 4 Forms check boxes on a sheet.
(Your post suggests you're using the latter but I'll show code for both
types) A dropdown list (A,B,C,D) is in H8. The linked cells for the
Forms controls are P1:P4; -change this location in the code to match
your model.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$H$8" Then '//BETTER TO USE NAMED RANGE HERE
With Me
Select Case Target.Value
Case "A", "B"
'//Forms control links
With Sheets("Sheet1") '//edit to suit
.Range("P1:P2") = True: .Range("P3:P4") = False
End With
'//ActiveX controls
.CheckBox1.Value = True: .CheckBox2.Value = True
.CheckBox3.Value = False: .CheckBox4.Value = False

Case "C", "D"
'//Forms control links
With Sheets("Sheet1") '//edit to suit
.Range("P1:P2") = False: .Range("P3:P4") = True
End With
'//ActiveX controls
.CheckBox1.Value = False: .CheckBox2.Value = False
.CheckBox3.Value = True: .CheckBox4.Value = True
End Select
End With
End If
End Sub

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion