Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
ynissel
 
Posts: n/a
Default Macro to make all checkboxes false and clear all comboxes

My macro (that someone from here helped me with a while ago) works great.
But I added a combobox and that one doesnt clear when I execute the macro.
Combo 1,2,3, clear but the 4th doesnt ?
Any ideas ?
Here is my macro.
Thanks,
Yosef

Option Explicit
Sub testme01()

Dim OLEObj As OLEObject
For Each OLEObj In ActiveSheet.OLEObjects
If TypeOf OLEObj.Object Is MSForms.CheckBox Then
OLEObj.Object.Value = False
End If
Next OLEObj
Range("B2:B5").Select
Range("B5").Activate
Selection.ClearContents
End Sub
  #2   Report Post  
Jim Rech
 
Posts: n/a
Default

Combo 1,2,3, clear but the 4th doesnt ?

That's remarkable because the macro only affect checkboxes. I think you
need to add combobox specifc code

Sub testme02()
Dim OLEObj As OLEObject
For Each OLEObj In ActiveSheet.OLEObjects
If TypeOf OLEObj.Object Is MSForms.CheckBox Then
OLEObj.Object.Value = False
ElseIf TypeOf OLEObj.Object Is MSForms.ComboBox Then
OLEObj.Object.Clear
End If
Next OLEObj
End Sub


--
Jim
"ynissel" wrote in message
...
| My macro (that someone from here helped me with a while ago) works great.
| But I added a combobox and that one doesnt clear when I execute the macro.
| Combo 1,2,3, clear but the 4th doesnt ?
| Any ideas ?
| Here is my macro.
| Thanks,
| Yosef
|
| Option Explicit
| Sub testme01()
|
| Dim OLEObj As OLEObject
| For Each OLEObj In ActiveSheet.OLEObjects
| If TypeOf OLEObj.Object Is MSForms.CheckBox Then
| OLEObj.Object.Value = False
| End If
| Next OLEObj
| Range("B2:B5").Select
| Range("B5").Activate
| Selection.ClearContents
| End Sub


  #3   Report Post  
ynissel
 
Posts: n/a
Default

OK. Ill try it. But Im not sure why theother 3 clear ?

Just tried and I got an error on
OLEObj.Object.clear

Is the syntax correct ?
Thanks again,
Yosef

"Jim Rech" wrote:

Combo 1,2,3, clear but the 4th doesnt ?


That's remarkable because the macro only affect checkboxes. I think you
need to add combobox specifc code

Sub testme02()
Dim OLEObj As OLEObject
For Each OLEObj In ActiveSheet.OLEObjects
If TypeOf OLEObj.Object Is MSForms.CheckBox Then
OLEObj.Object.Value = False
ElseIf TypeOf OLEObj.Object Is MSForms.ComboBox Then
OLEObj.Object.Clear
End If
Next OLEObj
End Sub


--
Jim
"ynissel" wrote in message
...
| My macro (that someone from here helped me with a while ago) works great.
| But I added a combobox and that one doesnt clear when I execute the macro.
| Combo 1,2,3, clear but the 4th doesnt ?
| Any ideas ?
| Here is my macro.
| Thanks,
| Yosef
|
| Option Explicit
| Sub testme01()
|
| Dim OLEObj As OLEObject
| For Each OLEObj In ActiveSheet.OLEObjects
| If TypeOf OLEObj.Object Is MSForms.CheckBox Then
| OLEObj.Object.Value = False
| End If
| Next OLEObj
| Range("B2:B5").Select
| Range("B5").Activate
| Selection.ClearContents
| End Sub



  #4   Report Post  
Jim Rech
 
Posts: n/a
Default

Is the syntax correct ?

Yes. I always run code before I post it. Maybe we're running different
Excel versions. Something weird is happening since your code that checks
for checkboxes (If TypeOf OLEObj.Object Is MSForms.CheckBox Then) before
doing anything should not be clearing combos.

--
Jim
"ynissel" wrote in message
...
| OK. Ill try it. But Im not sure why theother 3 clear ?
|
| Just tried and I got an error on
| OLEObj.Object.clear
|
| Is the syntax correct ?
| Thanks again,
| Yosef
|
| "Jim Rech" wrote:
|
| Combo 1,2,3, clear but the 4th doesnt ?
|
| That's remarkable because the macro only affect checkboxes. I think you
| need to add combobox specifc code
|
| Sub testme02()
| Dim OLEObj As OLEObject
| For Each OLEObj In ActiveSheet.OLEObjects
| If TypeOf OLEObj.Object Is MSForms.CheckBox Then
| OLEObj.Object.Value = False
| ElseIf TypeOf OLEObj.Object Is MSForms.ComboBox Then
| OLEObj.Object.Clear
| End If
| Next OLEObj
| End Sub
|
|
| --
| Jim
| "ynissel" wrote in message
| ...
| | My macro (that someone from here helped me with a while ago) works
great.
| | But I added a combobox and that one doesnt clear when I execute the
macro.
| | Combo 1,2,3, clear but the 4th doesnt ?
| | Any ideas ?
| | Here is my macro.
| | Thanks,
| | Yosef
| |
| | Option Explicit
| | Sub testme01()
| |
| | Dim OLEObj As OLEObject
| | For Each OLEObj In ActiveSheet.OLEObjects
| | If TypeOf OLEObj.Object Is MSForms.CheckBox Then
| | OLEObj.Object.Value = False
| | End If
| | Next OLEObj
| | Range("B2:B5").Select
| | Range("B5").Activate
| | Selection.ClearContents
| | End Sub
|
|
|


  #5   Report Post  
ynissel
 
Posts: n/a
Default

Sorry - I didnt mean to imply you didnt :-)
I am running EXcel 2003.
This is my current marco -and it does clear the first 3 comboboxes.

Dim OLEObj As OLEObject
'For Each OLEObj In ActiveSheet.OLEObjects
' If TypeOf OLEObj.Object Is MSForms.CheckBox Then
' OLEObj.Object.Value = False
' End If
'Next OLEObj
' Range("B2,B4,B5").Select
'Range("B5").Activate
'Selection.ClearContents


When I copied yours in I get a runtime error and when I debug it highlights

OLEObj.Object.Clear

Any ideas ?
Thanks,
Yosef

"Jim Rech" wrote:

Is the syntax correct ?


Yes. I always run code before I post it. Maybe we're running different
Excel versions. Something weird is happening since your code that checks
for checkboxes (If TypeOf OLEObj.Object Is MSForms.CheckBox Then) before
doing anything should not be clearing combos.

--
Jim
"ynissel" wrote in message
...
| OK. Ill try it. But Im not sure why theother 3 clear ?
|
| Just tried and I got an error on
| OLEObj.Object.clear
|
| Is the syntax correct ?
| Thanks again,
| Yosef
|
| "Jim Rech" wrote:
|
| Combo 1,2,3, clear but the 4th doesnt ?
|
| That's remarkable because the macro only affect checkboxes. I think you
| need to add combobox specifc code
|
| Sub testme02()
| Dim OLEObj As OLEObject
| For Each OLEObj In ActiveSheet.OLEObjects
| If TypeOf OLEObj.Object Is MSForms.CheckBox Then
| OLEObj.Object.Value = False
| ElseIf TypeOf OLEObj.Object Is MSForms.ComboBox Then
| OLEObj.Object.Clear
| End If
| Next OLEObj
| End Sub
|
|
| --
| Jim
| "ynissel" wrote in message
| ...
| | My macro (that someone from here helped me with a while ago) works
great.
| | But I added a combobox and that one doesnt clear when I execute the
macro.
| | Combo 1,2,3, clear but the 4th doesnt ?
| | Any ideas ?
| | Here is my macro.
| | Thanks,
| | Yosef
| |
| | Option Explicit
| | Sub testme01()
| |
| | Dim OLEObj As OLEObject
| | For Each OLEObj In ActiveSheet.OLEObjects
| | If TypeOf OLEObj.Object Is MSForms.CheckBox Then
| | OLEObj.Object.Value = False
| | End If
| | Next OLEObj
| | Range("B2:B5").Select
| | Range("B5").Activate
| | Selection.ClearContents
| | End Sub
|
|
|





  #6   Report Post  
Dave Peterson
 
Posts: n/a
Default

I'm guessing that the reason you got 3 comboboxes to clear was that you used
linked cells in the B2:B5 range.

And when you cleared those cells, you cleared the combobox.

One quick and dirty solution would be to just clear that additional linked cell.

This portion:

Range("B2:B5").Select
Range("B5").Activate
Selection.ClearContents

could be replaced with:
range("b2:B5").clearcontents
(and B5 isn't actually selected!)

Just change that range to include the other linked cell in that statement:

range("b2:B6").clearcontents
or
range("b2:B5,d999").clearcontents

ps. I didn't get an error with Jim's code. But if I had a linked cell, it
didn't get cleared.

But this cleared the combobox and the linked cell:

Option Explicit
Sub testme02A()
Dim OLEObj As OLEObject
For Each OLEObj In ActiveSheet.OLEObjects
If TypeOf OLEObj.Object Is MSForms.CheckBox Then
OLEObj.Object.Value = False
ElseIf TypeOf OLEObj.Object Is MSForms.ComboBox Then
OLEObj.Object.Value = ""
End If
Next OLEObj
End Sub



ynissel wrote:

My macro (that someone from here helped me with a while ago) works great.
But I added a combobox and that one doesnt clear when I execute the macro.
Combo 1,2,3, clear but the 4th doesnt ?
Any ideas ?
Here is my macro.
Thanks,
Yosef

Option Explicit
Sub testme01()

Dim OLEObj As OLEObject
For Each OLEObj In ActiveSheet.OLEObjects
If TypeOf OLEObj.Object Is MSForms.CheckBox Then
OLEObj.Object.Value = False
End If
Next OLEObj
Range("B2:B5").Select
Range("B5").Activate
Selection.ClearContents
End Sub


--

Dave Peterson
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
Macros to delete check boxes GWB Direct Excel Discussion (Misc queries) 23 June 3rd 05 09:56 PM
link data to new workbook WYN Excel Discussion (Misc queries) 3 February 28th 05 06:19 AM


All times are GMT +1. The time now is 07:44 AM.

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"