#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default string


In the following code, I'm attempting to make all my checkboxes clear t
a .false state, using a for next loop, Instead of typing each box in.

I'm new to vb and am unsure how I use a string variable with th
checkbox objects. Have a look and see if you can help.

Thanks Dennis

Private Sub Cm1_Click()

Dim x As String

For c = 1 To 55
'Dim x As String
x = "a" + c
x.Value = False
next c
'instead of below
'a1.Value = False
'a2.Value = False
'a3, a4, a5,...
't1.Text = ""

End Su

--
terrysoper197
-----------------------------------------------------------------------
terrysoper1973's Profile: http://www.excelforum.com/member.php...fo&userid=3016
View this thread: http://www.excelforum.com/showthread.php?threadid=49892

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default string

Are these checkboxes in a userform or checkboxes on a worksheet?

If they're on a worksheet, are they from the Forms toolbar or from the Control
toolbox toolbar.

On a Userform:

Option Explicit
Private Sub CommandButton1_Click()
Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeOf ctrl Is msforms.CheckBox Then
ctrl.Object.Value = False
End If
Next ctrl
End Sub

On a worksheet from the Forms toolbar:

Option Explicit
Sub testme()
Worksheets("Sheet1").CheckBoxes.Value = False
End Sub

One a worksheet from the Control Toolbox Toolbar:

Option Explicit
Private Sub CommandButton1_Click()
Dim OLEObj As OLEObject
For Each OLEObj In Me.OLEObjects
If TypeOf OLEObj.Object Is msforms.CheckBox Then
OLEObj.Object.Value = False
End If
Next OLEObj
End Sub

The me. keyword refers to the thing that owns the code--either the userform or
the worksheet with the button and checkboxes.


terrysoper1973 wrote:

In the following code, I'm attempting to make all my checkboxes clear to
a .false state, using a for next loop, Instead of typing each box in.

I'm new to vb and am unsure how I use a string variable with the
checkbox objects. Have a look and see if you can help.

Thanks Dennis

Private Sub Cm1_Click()

Dim x As String

For c = 1 To 55
'Dim x As String
x = "a" + c
x.Value = False
next c
'instead of below
'a1.Value = False
'a2.Value = False
'a3, a4, a5,...
't1.Text = ""

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


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default string


The checkboxes are in a worksheet, not sure about the other.

I've uploaded a sample for you.


+-------------------------------------------------------------------+
|Filename: fool balance.zip |
|Download: http://www.excelforum.com/attachment.php?postid=4191 |
+-------------------------------------------------------------------+

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default string

I don't use excelforum so I can't see the attachment.

But I wouldn't open an attachment anyway. (Lots of people won't.)

Better to post in plain text.

terrysoper1973 wrote:

The checkboxes are in a worksheet, not sure about the other.

I've uploaded a sample for you.

+-------------------------------------------------------------------+
|Filename: fool balance.zip |
|Download: http://www.excelforum.com/attachment.php?postid=4191 |
+-------------------------------------------------------------------+

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


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default string


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



  #6   Report Post  
Posted to microsoft.public.excel.programming
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



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
Change 3 letter text string to a number string Pete Excel Discussion (Misc queries) 3 December 31st 07 07:47 PM
counting the number of instances of a string within another string Keith R Excel Worksheet Functions 3 March 5th 07 06:54 PM
Splitting a text string into string and number mcambrose Excel Discussion (Misc queries) 4 February 21st 06 03:47 PM
to search for a string and affect data if it finds the string? Shwaman Excel Worksheet Functions 1 January 11th 06 12:56 AM
Create a formula into a String then assign string to a cell Myrna Larson[_2_] Excel Programming 6 August 23rd 03 09:42 PM


All times are GMT +1. The time now is 08:49 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"