Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default "For Each" Statement error...


Hi

I'm having a little trouble with "For each"...

I want to use this statement to know the number of checkboxes in my
form, for example...

It's kind of:

dim check as checkbox

For each check in my_form

i=i+1

Next check

But it doesn't work... I don't know if I'm using the statement
correctly...


--
pmguerra
------------------------------------------------------------------------
pmguerra's Profile: http://www.excelforum.com/member.php...o&userid=14986
View this thread: http://www.excelforum.com/showthread...hreadid=560898

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default "For Each" Statement error...

Dim ctl As MSForms.Control
Dim i as long

For Each ctl In UserForm1.Controls
If TypeName(ctl) = "CheckBox" Then
i = i + 1
End If
Next

msgbox i & " checkboxes"

RBS

"pmguerra" wrote in
message ...

Hi

I'm having a little trouble with "For each"...

I want to use this statement to know the number of checkboxes in my
form, for example...

It's kind of:

dim check as checkbox

For each check in my_form

i=i+1

Next check

But it doesn't work... I don't know if I'm using the statement
correctly...


--
pmguerra
------------------------------------------------------------------------
pmguerra's Profile:
http://www.excelforum.com/member.php...o&userid=14986
View this thread: http://www.excelforum.com/showthread...hreadid=560898


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default "For Each" Statement error...

This is how to do it

Dim ctl As Control

For Each ctl In Me.Controls
If TypeName(ctl) = "CheckBox" Then
MsgBox ctl.Caption
End If
Next ctl


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"pmguerra" wrote in
message ...

Hi

I'm having a little trouble with "For each"...

I want to use this statement to know the number of checkboxes in my
form, for example...

It's kind of:

dim check as checkbox

For each check in my_form

i=i+1

Next check

But it doesn't work... I don't know if I'm using the statement
correctly...


--
pmguerra
------------------------------------------------------------------------
pmguerra's Profile:

http://www.excelforum.com/member.php...o&userid=14986
View this thread: http://www.excelforum.com/showthread...hreadid=560898



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 644
Default "For Each" Statement error...

It's a little more complicated than that... try doing it this way.
Dim check As Control 'All types of controls
Dim i As Integer
For Each check In UserForm1.Controls 'Loop through each control in
userform1 controls
If TypeName(check) = "CheckBox" Then 'Because we are going
through all the controls we need to filter out just the "CheckBoxes"
i = i + 1
End If
Next
MsgBox i

HTH

Die_Another_Day
pmguerra wrote:
Hi

I'm having a little trouble with "For each"...

I want to use this statement to know the number of checkboxes in my
form, for example...

It's kind of:

dim check as checkbox

For each check in my_form

i=i+1

Next check

But it doesn't work... I don't know if I'm using the statement
correctly...


--
pmguerra
------------------------------------------------------------------------
pmguerra's Profile: http://www.excelforum.com/member.php...o&userid=14986
View this thread: http://www.excelforum.com/showthread...hreadid=560898


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default "For Each" Statement error...

One more...

Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeOf ctrl Is MSForms.CheckBox Then
ctrl.Object.Value = True
End If
Next ctrl



pmguerra wrote:

Hi

I'm having a little trouble with "For each"...

I want to use this statement to know the number of checkboxes in my
form, for example...

It's kind of:

dim check as checkbox

For each check in my_form

i=i+1

Next check

But it doesn't work... I don't know if I'm using the statement
correctly...

--
pmguerra
------------------------------------------------------------------------
pmguerra's Profile: http://www.excelforum.com/member.php...o&userid=14986
View this thread: http://www.excelforum.com/showthread...hreadid=560898


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default "For Each" Statement error...


Thank you very much!!! :

--
pmguerr
-----------------------------------------------------------------------
pmguerra's Profile: http://www.excelforum.com/member.php...fo&userid=1498
View this thread: http://www.excelforum.com/showthread.php?threadid=56089

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
embedding "ISERROR" function into an "IF" statement [email protected] Excel Worksheet Functions 8 January 4th 07 12:01 AM
Shortcut key for "Paste Options" and "Error Checking" buttons? johndog Excel Discussion (Misc queries) 1 October 6th 06 11:56 AM
What is Error "Method "Paste" of object "_Worksheet" failed? vat Excel Programming 7 February 17th 06 08:05 PM
Getting "compile error" "method or data member not found" on reinstall Bp Excel Programming 1 April 23rd 04 04:42 PM
Need help in excel with "Statement invalid outside Type block. " error Brent[_6_] Excel Programming 3 January 17th 04 03:03 AM


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