Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default Clearing All check boxes using Macro

Hi,

I'm trying to uncheck all the check boxes using a macro.

Private Sub Clearall()
Dim ws As Worksheet
Dim chkbx As OLEObject

For Each chkbx In ws.OLEObjects
chkbx.Object.Value = False
Next chkbx
End Sub

and I'm getting an error Run time error-"91":
Object variable or With block variable not set.

Please Help



  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,202
Default Clearing All check boxes using Macro

This code will clear any and all the CheckBoxes on the ActiveSheet...

Sub ClearAllCheckBoxes()
Dim ChkBox As OLEObject
With ActiveSheet
.CheckBoxes.Value = False
For Each ChkBox In .OLEObjects
ChkBox.Object.Value = False
Next
End With
End Sub

If you want to specify a particular worksheet, change the ActiveSheet
reference in the With statement to the worksheet you want to specify.

Rick


"Anil Kumar N." <Anil Kumar wrote in message
...
Hi,

I'm trying to uncheck all the check boxes using a macro.

Private Sub Clearall()
Dim ws As Worksheet
Dim chkbx As OLEObject

For Each chkbx In ws.OLEObjects
chkbx.Object.Value = False
Next chkbx
End Sub

and I'm getting an error Run time error-"91":
Object variable or With block variable not set.

Please Help




  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4
Default Clearing All check boxes using Macro

Thanks a ton Rick,

"Rick Rothstein (MVP - VB)" wrote:

This code will clear any and all the CheckBoxes on the ActiveSheet...

Sub ClearAllCheckBoxes()
Dim ChkBox As OLEObject
With ActiveSheet
.CheckBoxes.Value = False
For Each ChkBox In .OLEObjects
ChkBox.Object.Value = False
Next
End With
End Sub

If you want to specify a particular worksheet, change the ActiveSheet
reference in the With statement to the worksheet you want to specify.

Rick


"Anil Kumar N." <Anil Kumar wrote in message
...
Hi,

I'm trying to uncheck all the check boxes using a macro.

Private Sub Clearall()
Dim ws As Worksheet
Dim chkbx As OLEObject

For Each chkbx In ws.OLEObjects
chkbx.Object.Value = False
Next chkbx
End Sub

and I'm getting an error Run time error-"91":
Object variable or With block variable not set.

Please Help





  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10,593
Default Clearing All check boxes using Macro

You need to set ws to something, such as activesheet

Private Sub Clearall()
Dim ws As Worksheet
Dim chkbx As OLEObject

Set ws = ActiveSheet
For Each chkbx In ws.OLEObjects
chkbx.Object.Value = False
Next chkbx
End Sub



--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Anil Kumar N." <Anil Kumar wrote in message
...
Hi,

I'm trying to uncheck all the check boxes using a macro.

Private Sub Clearall()
Dim ws As Worksheet
Dim chkbx As OLEObject

For Each chkbx In ws.OLEObjects
chkbx.Object.Value = False
Next chkbx
End Sub

and I'm getting an error Run time error-"91":
Object variable or With block variable not set.

Please Help





  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,202
Default Clearing All check boxes using Macro

Looks like I missed one test condition... my routine needs an

On Error Resume Next

statement to handle the possibility that no Form's CheckBoxes exist on the
sheet...

Sub ClearAllCheckBoxes()
Dim ChkBox As OLEObject
With ActiveSheet
On Error Resume Next
.CheckBoxes.Value = False
For Each ChkBox In .OLEObjects
ChkBox.Object.Value = False
Next
End With
End Sub

Rick


"Rick Rothstein (MVP - VB)" wrote in
message ...
This code will clear any and all the CheckBoxes on the ActiveSheet...

Sub ClearAllCheckBoxes()
Dim ChkBox As OLEObject
With ActiveSheet
.CheckBoxes.Value = False
For Each ChkBox In .OLEObjects
ChkBox.Object.Value = False
Next
End With
End Sub

If you want to specify a particular worksheet, change the ActiveSheet
reference in the With statement to the worksheet you want to specify.

Rick


"Anil Kumar N." <Anil Kumar wrote in message
...
Hi,

I'm trying to uncheck all the check boxes using a macro.

Private Sub Clearall()
Dim ws As Worksheet
Dim chkbx As OLEObject

For Each chkbx In ws.OLEObjects
chkbx.Object.Value = False
Next chkbx
End Sub

and I'm getting an error Run time error-"91":
Object variable or With block variable not set.

Please Help





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
Can one macro serve several check boxes? Naum Charts and Charting in Excel 3 November 16th 07 04:55 PM
Clearing Check Boxes & Running a diff Macro when unchecking the ch Vick Excel Discussion (Misc queries) 6 May 30th 07 08:44 PM
Clearing Check Boxes and Cells Mel Excel Discussion (Misc queries) 1 May 26th 05 05:13 AM
Clearing Check Boxes and Cells Mel Excel Discussion (Misc queries) 1 May 25th 05 09:00 PM
Clearing Check Boxes and Cells Mel Excel Worksheet Functions 0 May 25th 05 05:52 PM


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