Thread: string
View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default string

You can do something like the following:

Dim Ndx As Long
For Ndx = 1 To 2
UserForm1.Controls("A" & Ndx).Value = False
Next Ndx

Or, to clear all checkboxes,

Dim Ctrl As MSForms.Control
For Each Ctrl In UserForm1.Controls
If TypeOf Ctrl Is MSForms.CheckBox Then
Ctrl.Value = False
End If
Next Ctrl

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"terrysoper1973"
<terrysoper1973.21a5pm_1136663701.3341@excelforu m-nospam.com
wrote in message
news:terrysoper1973.21a5pm_1136663701.3341@excelfo rum-nospam.com...

To clear all the checkboxes can be done by putting the statment
a1.value = false for each checkbox, however, there would be a
lot of
code if I need 100-200 checkboxes; so I'm asking if it is
possible set
up a for next loop that replaces the a1.value = false, a2.value
=
false, a3.value = false... with a simple sting that replaces
the a#
part of the object with an
a(string).value = false, but I'm not sure about the syntax, or
if it is
even possible.

Please help, and sorry about the file upload, we all have to be
careful
about what we open, won't happen again.

The code below is used to simulate my excel sheet.


Private Sub a1_Click()
'first check box test
Worksheets("sheet1").t1.Text = "fool"

End Sub

Private Sub a2_Click()
'second check box in sheet
Worksheets("sheet1").t1.Text = "fool2"
End Sub

Private Sub Cm1_Click()
'command button to make all checkboxes false

'works until x.value = false line, stops at the x
'For c = 1 To 2
'Dim x As String
'x = "a" + c
'x.Value = False
'next c

'works
'a2.Value = False
'a3, a4, a5,...
't1.Text = ""

End Sub

Private Sub Worksheet_Activate()
'works

a1.Value = False
a2.Value = False

End Sub


--
terrysoper1973
------------------------------------------------------------------------
terrysoper1973's Profile:
http://www.excelforum.com/member.php...o&userid=30161
View this thread:
http://www.excelforum.com/showthread...hreadid=498925