Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Looping through controls on form

Good Morning,

I have 6 checkboxes grouped (grpMaterials) within a frame on a form. If the
value of a checkbox is true, the following happens within a certain range of
cells on my worksheet:

If chkTextbook.Value = True Then
.Offset(0, 26).Value = Chr(82)
End If

The value of the second checkbox would appear in rng.Offset(0, 27), the
third in rng.offset(0, 28), etc. If the value of the checkbox is false, the
corresponding cell would be blank.

How would I loop through the controls instead of having to write the above
code for each of the checkboxes?

Thank you much,

Robbyn


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Looping through controls on form


Dim ctl As msforms.Control
Dim i As Long

i = 25
For Each ctl In Me.Controls
If TypeName(ctl) = "CheckBox" Then
i = i + 1
If ctl.Value Then
.Offset(0, i).Value = Chr(82)
End If
End If
Next ctl


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Robbyn" wrote in message
...
Good Morning,

I have 6 checkboxes grouped (grpMaterials) within a frame on a form. If

the
value of a checkbox is true, the following happens within a certain range

of
cells on my worksheet:

If chkTextbook.Value = True Then
.Offset(0, 26).Value = Chr(82)
End If

The value of the second checkbox would appear in rng.Offset(0, 27), the
third in rng.offset(0, 28), etc. If the value of the checkbox is false,

the
corresponding cell would be blank.

How would I loop through the controls instead of having to write the above
code for each of the checkboxes?

Thank you much,

Robbyn




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Looping through controls on form

Thanks Bob! Worked perfectly!

"Bob Phillips" wrote:


Dim ctl As msforms.Control
Dim i As Long

i = 25
For Each ctl In Me.Controls
If TypeName(ctl) = "CheckBox" Then
i = i + 1
If ctl.Value Then
.Offset(0, i).Value = Chr(82)
End If
End If
Next ctl


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Robbyn" wrote in message
...
Good Morning,

I have 6 checkboxes grouped (grpMaterials) within a frame on a form. If

the
value of a checkbox is true, the following happens within a certain range

of
cells on my worksheet:

If chkTextbook.Value = True Then
.Offset(0, 26).Value = Chr(82)
End If

The value of the second checkbox would appear in rng.Offset(0, 27), the
third in rng.offset(0, 28), etc. If the value of the checkbox is false,

the
corresponding cell would be blank.

How would I loop through the controls instead of having to write the above
code for each of the checkboxes?

Thank you much,

Robbyn





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
ActiveX Controls vs Form Controls Alex Excel Discussion (Misc queries) 1 January 11th 06 08:46 AM
Problem with looping through userform controls Jeremy Gollehon[_2_] Excel Programming 5 February 17th 05 05:41 PM
looping through userform controls JulieD Excel Programming 2 August 14th 04 02:13 PM
Looping through multiple controls rci Excel Programming 2 March 4th 04 08:43 PM
Looping thru custom controls papou[_6_] Excel Programming 2 July 23rd 03 04:14 PM


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