Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Help with Selecting multiple Checkboxes on a form

I am trying to use a CommnadButton on a form to Select ALL Checkboxes on a
form IF the CheckBox Caption is NOT "----------".
However i keep getting a error on the below identified line, why ?

Private Sub CommandButton2_Click()
Dim chx As CheckBox
With UserForm6
If chx.Caption < "----------" Then '<==== ERROR
For Each chx In UserForm6
chx.box = True
Next chx
End If
End With
End Sub

How can i fix this?

Corey....


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Help with Selecting multiple Checkboxes on a form

Hi Corey,

If you want to use the variable instead of the checkbox name you need to
assign a checkbox to it first otherwise how does it know which checkbox
caption you are referring to. Because you are using chx in the For Each loop,
perhaps simply using the actual name of the checkbox to identify the caption.


--
Regards,

OssieMac


"Corey ...." wrote:

I am trying to use a CommnadButton on a form to Select ALL Checkboxes on a
form IF the CheckBox Caption is NOT "----------".
However i keep getting a error on the below identified line, why ?

Private Sub CommandButton2_Click()
Dim chx As CheckBox
With UserForm6
If chx.Caption < "----------" Then '<==== ERROR
For Each chx In UserForm6
chx.box = True
Next chx
End If
End With
End Sub

How can i fix this?

Corey....



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Help with Selecting multiple Checkboxes on a form

Adding to Ossie's observation, moving your If statement inside the For ...
Next loop will accomplish the variable assignment through the For Each chx
part of the statement. Then you will need to fix the statembent:

chx.box = True

Looks like it should be just:

chx = True

"Corey ...." wrote:

I am trying to use a CommnadButton on a form to Select ALL Checkboxes on a
form IF the CheckBox Caption is NOT "----------".
However i keep getting a error on the below identified line, why ?

Private Sub CommandButton2_Click()
Dim chx As CheckBox
With UserForm6
If chx.Caption < "----------" Then '<==== ERROR
For Each chx In UserForm6
chx.box = True
Next chx
End If
End With
End Sub

How can i fix this?

Corey....



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Help with Selecting multiple Checkboxes on a form

You also need to modify this line:

For Each chx In UserForm6

To:

For Each chx In UserForm6.Controls

This assumes you only have checkboxes on the form.

"Corey ...." wrote:

I am trying to use a CommnadButton on a form to Select ALL Checkboxes on a
form IF the CheckBox Caption is NOT "----------".
However i keep getting a error on the below identified line, why ?

Private Sub CommandButton2_Click()
Dim chx As CheckBox
With UserForm6
If chx.Caption < "----------" Then '<==== ERROR
For Each chx In UserForm6
chx.box = True
Next chx
End If
End With
End Sub

How can i fix this?

Corey....



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Help with Selecting multiple Checkboxes on a form

One more adjustment. To get the checkmark to show:

chx.Value = True

"Corey ...." wrote:

I am trying to use a CommnadButton on a form to Select ALL Checkboxes on a
form IF the CheckBox Caption is NOT "----------".
However i keep getting a error on the below identified line, why ?

Private Sub CommandButton2_Click()
Dim chx As CheckBox
With UserForm6
If chx.Caption < "----------" Then '<==== ERROR
For Each chx In UserForm6
chx.box = True
Next chx
End If
End With
End Sub

How can i fix this?

Corey....





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Help with Selecting multiple Checkboxes on a form

Option Explicit
Private Sub CommandButton2_Click()
Dim ctrl As control 'msforms.CheckBox
for each ctrl in me.controls
if typeof ctrl is msforms.checkbox then
if ctrl.caption = "----------" then
'do nothing
else
ctrl.value = true
end if
end if
next ctrl
End Sub

"Corey ...." wrote:

I am trying to use a CommnadButton on a form to Select ALL Checkboxes on a
form IF the CheckBox Caption is NOT "----------".
However i keep getting a error on the below identified line, why ?

Private Sub CommandButton2_Click()
Dim chx As CheckBox
With UserForm6
If chx.Caption < "----------" Then '<==== ERROR
For Each chx In UserForm6
chx.box = True
Next chx
End If
End With
End Sub

How can i fix this?

Corey....


--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Help with Selecting multiple Checkboxes on a form

Thank you guys.

Got it working now.
Now for the next issue/topic?
"Corey ...." wrote in message
...
I am trying to use a CommnadButton on a form to Select ALL Checkboxes on a
form IF the CheckBox Caption is NOT "----------".
However i keep getting a error on the below identified line, why ?

Private Sub CommandButton2_Click()
Dim chx As CheckBox
With UserForm6
If chx.Caption < "----------" Then '<==== ERROR
For Each chx In UserForm6
chx.box = True
Next chx
End If
End With
End Sub

How can i fix this?

Corey....



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
How to clear all checkboxes on a form? Arlen Excel Worksheet Functions 2 May 6th 10 04:20 PM
uncheck checkboxes from a form Bob Phillips Excel Programming 1 January 8th 07 01:08 AM
Adding Checkboxes to a Form Bill[_30_] Excel Programming 3 June 26th 06 11:57 PM
Selecting many Checkboxes to align & size Saz[_6_] Excel Programming 3 June 7th 06 05:01 PM
selecting values form multiple excel files into an excel worksheet martha Excel Programming 1 June 27th 05 10:17 AM


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