Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Loop for check boxes

Below is the code I have. i haven't written code in a long time and can't
remember how to write a loop for this - i have about 20 sets of four check
boxes and don't want to do this for every one of them - Thanks to any one who
can help

------
Private Sub CheckBox1_Click()
If CheckBox1 = True Then
CheckBox2 = False
CheckBox3 = False
CheckBox4 = False
End If
End Sub




Private Sub CheckBox2_Click()
If CheckBox2 = True Then
CheckBox1 = False
CheckBox3 = False
CheckBox4 = False
End If
End Sub

Private Sub CheckBox3_Click()
If CheckBox3 = True Then
CheckBox1 = False
CheckBox2 = False
CheckBox4 = False
End If
End Sub

Private Sub CheckBox4_Click()
If CheckBox4 = True Then
CheckBox1 = False
CheckBox2 = False
CheckBox3 = False
End If
End Sub
--
Karissa
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default Loop for check boxes

Hi Karissa,

If you use OptionButtons, rather than CheckBoxes, this behaviour will
be automatic.

Put OptionButtons within unique Frames to get them to behave as a
group.

Let me know if I've misunderstood you.

Br,
NickH
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Loop for check boxes

Are the checkboxes numbered 1 thru 80 on a sheet or are the on individual
form and numbered 1 thru 4 on each form? If they are on the forms, you could
just copy the code 19 times to the checkbox1 on the other forms.

As far as looping to write the code for the 1 thru 80, it could get pretty
hairy.

"Karissa" wrote:

Below is the code I have. i haven't written code in a long time and can't
remember how to write a loop for this - i have about 20 sets of four check
boxes and don't want to do this for every one of them - Thanks to any one who
can help

------
Private Sub CheckBox1_Click()
If CheckBox1 = True Then
CheckBox2 = False
CheckBox3 = False
CheckBox4 = False
End If
End Sub




Private Sub CheckBox2_Click()
If CheckBox2 = True Then
CheckBox1 = False
CheckBox3 = False
CheckBox4 = False
End If
End Sub

Private Sub CheckBox3_Click()
If CheckBox3 = True Then
CheckBox1 = False
CheckBox2 = False
CheckBox4 = False
End If
End Sub

Private Sub CheckBox4_Click()
If CheckBox4 = True Then
CheckBox1 = False
CheckBox2 = False
CheckBox3 = False
End If
End Sub
--
Karissa

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Loop for check boxes

Just to add -

As Nick suggests OptionButtons work like Radio-buttons, press one and all
others are off. With ActiveX OptionButtons (looks like you have aX
Checkboxes) you can have sets of mutually exclusive OB's by assigning the
GroupName property to suit.

In Design mode, click properties and change GroupName's to suit.

Here's some code to make a new set of 20 sets of 4 optionbuttons

Suggest do not run this code in the same project of the activesheet. Also do
not "break" or step into the code.

Sub AddOBs()
Dim ole As OLEObject
Dim i As Long, j As Long

For i = 1 To 20
For j = 1 To 4
Set ole = ActiveSheet.OLEObjects.Add("Forms.OptionButton.1")

With ole
.Left = (j - 1) * 150 + 10
.Top = (i - 1) * 50 + 10
.Name = "OB_" & i & "_" & j
.Object.GroupName = "Set_" & i
.Object.Caption = "Set " & i & " Choice " & j
End With
Next
Next

End Sub


Regards,
Peter T





If you go with Nick's suggestion (and probably you should), you can

"NickH" wrote in message
...
Hi Karissa,

If you use OptionButtons, rather than CheckBoxes, this behaviour will
be automatic.

Put OptionButtons within unique Frames to get them to behave as a
group.

Let me know if I've misunderstood you.

Br,
NickH



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Loop for check boxes

Thanks to all - The option boxes worked the tip on the Group name helped. I
wasn't sure how to make just the four in a row link together without using
the group box (that would have been messy).

--
Karissa


"JLGWhiz" wrote:

Are the checkboxes numbered 1 thru 80 on a sheet or are the on individual
form and numbered 1 thru 4 on each form? If they are on the forms, you could
just copy the code 19 times to the checkbox1 on the other forms.

As far as looping to write the code for the 1 thru 80, it could get pretty
hairy.

"Karissa" wrote:

Below is the code I have. i haven't written code in a long time and can't
remember how to write a loop for this - i have about 20 sets of four check
boxes and don't want to do this for every one of them - Thanks to any one who
can help

------
Private Sub CheckBox1_Click()
If CheckBox1 = True Then
CheckBox2 = False
CheckBox3 = False
CheckBox4 = False
End If
End Sub




Private Sub CheckBox2_Click()
If CheckBox2 = True Then
CheckBox1 = False
CheckBox3 = False
CheckBox4 = False
End If
End Sub

Private Sub CheckBox3_Click()
If CheckBox3 = True Then
CheckBox1 = False
CheckBox2 = False
CheckBox4 = False
End If
End Sub

Private Sub CheckBox4_Click()
If CheckBox4 = True Then
CheckBox1 = False
CheckBox2 = False
CheckBox3 = False
End If
End Sub
--
Karissa

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
Copy and move check box (check boxes) with new cell link? Marty Excel Worksheet Functions 1 January 20th 10 07:43 PM
returning back to loop check condition without completing the loop ashish128 Excel Programming 13 April 3rd 08 12:53 PM
Loop through column(s) to check values, perform action based on check ward376 Excel Programming 4 November 6th 07 03:21 PM
Enable check box in protected sheet + group check boxes Dexxterr Excel Discussion (Misc queries) 4 August 2nd 06 12:00 PM
How do i create a value for check boxes or option boxes Tim wr Excel Discussion (Misc queries) 1 February 9th 06 10:29 PM


All times are GMT +1. The time now is 06:12 AM.

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"