Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 142
Default Arrays of Controls

I would like to create a form with a large number of checkboxes. I would
like to be able to set their values and possibly other properties and
retrieve their values in a look rather than have long strings of code
reference each checkbox bt name. Is there any way to accomplish that?

Thank you.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Arrays of Controls

I think the answer is gonna depend on what kind of checkboxes these are and
where they're located.

If they're checkboxes from the Forms toolbar and they're placed on a sheet, you
could loop through them with something like this:

Option Explicit
Sub testme()
dim cbx as checkbox
for each cbx in worksheets("Somesheetnamehere").checkboxes
msgbox cbx.name & vblf & cbx.value
next cbx
end sub

If they're checkboxes from the control toolbox toolbar placed on a worksheet:

Option Explicit
Sub testme()
Dim OLEObj as oleobject
for each oleobj in worksheets("Somesheetnamehere").oleobjects
if typeof oleobj.object is msforms.checkbox then
msgbox oleobj.name & vblf & oleobj.object.value
end if
next oleobj
end sub

If the checkbox is on a userform (designed in the VBE, not just a worksheet set
up to look like a form), the code is very close to the OLEObject code:


Option Explicit
Private Sub CommandButton1_Click()
Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeOf ctrl Is msforms.CheckBox Then
MsgBox ctrl.Name & vbLf & ctrl.Value
End If
Next ctrl
End Sub

======
If you wanted to use common code for either the checkboxes from the control
toolbox toolbar (placed on a sheet) or the checkboxes on a userform, you can use
this technique from John Walkenbach:

http://spreadsheetpage.com/index.php...one_procedure/

He uses Commandbuttons in his example, but the code would be very similar.

=======
If you wanted to use common code for the checkboxes from the Forms toolbar
(placed on a worksheet), you can just assign the same macro to each of the
checkboxes.



wrote:

I would like to create a form with a large number of checkboxes. I would
like to be able to set their values and possibly other properties and
retrieve their values in a look rather than have long strings of code
reference each checkbox bt name. Is there any way to accomplish that?

Thank you.


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Arrays of Controls

ps.

VBA doesn't allow you to use this kind of control array (like VB???).

Dave Peterson wrote:

I think the answer is gonna depend on what kind of checkboxes these are and
where they're located.

If they're checkboxes from the Forms toolbar and they're placed on a sheet, you
could loop through them with something like this:

Option Explicit
Sub testme()
dim cbx as checkbox
for each cbx in worksheets("Somesheetnamehere").checkboxes
msgbox cbx.name & vblf & cbx.value
next cbx
end sub

If they're checkboxes from the control toolbox toolbar placed on a worksheet:

Option Explicit
Sub testme()
Dim OLEObj as oleobject
for each oleobj in worksheets("Somesheetnamehere").oleobjects
if typeof oleobj.object is msforms.checkbox then
msgbox oleobj.name & vblf & oleobj.object.value
end if
next oleobj
end sub

If the checkbox is on a userform (designed in the VBE, not just a worksheet set
up to look like a form), the code is very close to the OLEObject code:

Option Explicit
Private Sub CommandButton1_Click()
Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeOf ctrl Is msforms.CheckBox Then
MsgBox ctrl.Name & vbLf & ctrl.Value
End If
Next ctrl
End Sub

======
If you wanted to use common code for either the checkboxes from the control
toolbox toolbar (placed on a sheet) or the checkboxes on a userform, you can use
this technique from John Walkenbach:

http://spreadsheetpage.com/index.php...one_procedure/

He uses Commandbuttons in his example, but the code would be very similar.

=======
If you wanted to use common code for the checkboxes from the Forms toolbar
(placed on a worksheet), you can just assign the same macro to each of the
checkboxes.

wrote:

I would like to create a form with a large number of checkboxes. I would
like to be able to set their values and possibly other properties and
retrieve their values in a look rather than have long strings of code
reference each checkbox bt name. Is there any way to accomplish that?

Thank you.


--

Dave Peterson


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default Arrays of Controls

This should get you started:
http://www.youtube.com/watch?v=b3kq9PDkGKM

Look on YouTube for other, similar, videos.

--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


" wrote:

I would like to create a form with a large number of checkboxes. I would
like to be able to set their values and possibly other properties and
retrieve their values in a look rather than have long strings of code
reference each checkbox bt name. Is there any way to accomplish that?

Thank you.
.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 142
Default Arrays of Controls

Thanks - That will work great!

On Fri, 04 Jun 2010 17:34:57 -0500, Dave Peterson
wrote:


If the checkbox is on a userform (designed in the VBE, not just a worksheet set
up to look like a form), the code is very close to the OLEObject code:


Option Explicit
Private Sub CommandButton1_Click()
Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeOf ctrl Is msforms.CheckBox Then
MsgBox ctrl.Name & vbLf & ctrl.Value
End If
Next ctrl
End Sub


wrote:

I would like to create a form with a large number of checkboxes. I would
like to be able to set their values and possibly other properties and
retrieve their values in a look rather than have long strings of code
reference each checkbox bt name. Is there any way to accomplish that?

Thank you.


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
Trouble with arrays (transferring values between two arrays) Keith R[_2_] Excel Programming 4 November 14th 07 12:00 AM
Losing data in controls (and arrays) during unhandled exceptions. David Excel Programming 4 December 6th 06 07:17 PM
Working with ranges in arrays... or an introduction to arrays Glen Excel Programming 5 September 10th 06 08:32 AM
Arrays - declaration, adding values to arrays and calculation Maxi[_2_] Excel Programming 1 August 17th 06 04:13 PM
Event procedures for controls added with Controls.Add John Austin[_4_] Excel Programming 1 March 9th 05 03:31 PM


All times are GMT +1. The time now is 09:10 PM.

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"