ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   making checkbox into a variable (https://www.excelbanter.com/excel-programming/362796-re-making-checkbox-into-variable.html)

minastirith

making checkbox into a variable
 

Hello,

I want to make the checkbox suffix number into a variable so that I can
loop the whole process instead of doing this long process until
CheckBox120:


Code:
--------------------
Private Sub CommandButton1_Click()
Dim startrow%
startrow = 1
If CheckBox1.value Then Call Variables(startrow)
End If
If CheckBox2.value Then Call Variables(startrow + 2)
End If
If CheckBox3.value Then Call Variables(startrow + 3)
End If
End Sub
--------------------


I tried to do this but it doesn't work.


Code:
--------------------
Private Sub CommandButton1_Click()
For startrow = 1 To 120
If CheckBox + startrow + .value Then
Call Variables(startrow)
End If
Next startrow
End Sub
--------------------


Thanks a lot for your help


--
minastirith
------------------------------------------------------------------------
minastirith's Profile: http://www.excelforum.com/member.php...o&userid=34941
View this thread: http://www.excelforum.com/showthread...hreadid=546729


Tom Ogilvy

making checkbox into a variable
 
are they on a userform

Dim cbx as MSForms.CheckBox
for i = 1 to 5
set cbx = userform1.Controls("CheckBox" & i)
msgbox cbx.caption
Next

if on a worksheet

dim cbx as MSForms.checkbox
for i = 1 to 5
set cbx = activesheet.OleObjects("Checkbox" & i).Object
msgbox cbx.caption
Next i

--
Regards,
Tom Ogilvy


"minastirith" wrote:


Hello,

I want to make the checkbox suffix number into a variable so that I can
loop the whole process instead of doing this long process until
CheckBox120:


Code:
--------------------
Private Sub CommandButton1_Click()
Dim startrow%
startrow = 1
If CheckBox1.value Then Call Variables(startrow)
End If
If CheckBox2.value Then Call Variables(startrow + 2)
End If
If CheckBox3.value Then Call Variables(startrow + 3)
End If
End Sub
--------------------


I tried to do this but it doesn't work.


Code:
--------------------
Private Sub CommandButton1_Click()
For startrow = 1 To 120
If CheckBox + startrow + .value Then
Call Variables(startrow)
End If
Next startrow
End Sub
--------------------


Thanks a lot for your help


--
minastirith
------------------------------------------------------------------------
minastirith's Profile: http://www.excelforum.com/member.php...o&userid=34941
View this thread: http://www.excelforum.com/showthread...hreadid=546729




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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com