PC Review


Reply
Thread Tools Rate Thread

clearing cells and checkboxes **ROOKIE HERE**

 
 
Dan
Guest
Posts: n/a
 
      20th Feb 2007
Hello -

I am a VBA rookie and am trying to write an Excel Macro which will
clear contents of a cell along with any check boxes and option
buttons. I got the first part of the macro correct, but when I tried
adding additional checkboxes and options to it, it just don't work.

Here is my code:

Private Sub CommandButton1_Click()
Dim cell As Range
For Each cell In ActiveSheet.UsedRange
If cell.Locked = False Then cell.MergeArea.ClearContents
If OptionButton1.Value = 0 Then OptionButton1.ClearContents
If CheckBox1.Value = 0 Then CheckBox1.ClearContents
Next
End Sub

Thanks for any help someone can provide.
Dan

 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      20th Feb 2007
I think something like this would work ok:

Option Explicit
Private Sub CommandButton1_Click()
Dim cell As Range
Dim OLEObj As OLEObject

For Each cell In Me.UsedRange
If cell.Locked = False Then
cell.MergeArea.Value = ""
End If
Next cell

For Each OLEObj In Me.OLEObjects
If TypeOf OLEObj.Object Is MSForms.OptionButton Then
OLEObj.Object.Value = False
ElseIf TypeOf OLEObj.Object Is MSForms.CheckBox Then
OLEObj.Object.Value = False
End If
Next OLEObj
End Sub




Dan wrote:
>
> Hello -
>
> I am a VBA rookie and am trying to write an Excel Macro which will
> clear contents of a cell along with any check boxes and option
> buttons. I got the first part of the macro correct, but when I tried
> adding additional checkboxes and options to it, it just don't work.
>
> Here is my code:
>
> Private Sub CommandButton1_Click()
> Dim cell As Range
> For Each cell In ActiveSheet.UsedRange
> If cell.Locked = False Then cell.MergeArea.ClearContents
> If OptionButton1.Value = 0 Then OptionButton1.ClearContents
> If CheckBox1.Value = 0 Then CheckBox1.ClearContents
> Next
> End Sub
>
> Thanks for any help someone can provide.
> Dan


--

Dave Peterson
 
Reply With Quote
 
Dan
Guest
Posts: n/a
 
      20th Feb 2007
On Feb 19, 5:05 pm, Dave Peterson <peter...@verizonXSPAM.net> wrote:
> I think something like this would work ok:
>
> Option Explicit
> Private Sub CommandButton1_Click()
> Dim cell As Range
> Dim OLEObj As OLEObject
>
> For Each cell In Me.UsedRange
> If cell.Locked = False Then
> cell.MergeArea.Value = ""
> End If
> Next cell
>
> For Each OLEObj In Me.OLEObjects
> If TypeOf OLEObj.Object Is MSForms.OptionButton Then
> OLEObj.Object.Value = False
> ElseIf TypeOf OLEObj.Object Is MSForms.CheckBox Then
> OLEObj.Object.Value = False
> End If
> Next OLEObj
> End Sub
>
>
>
>
>
> Dan wrote:
>
> > Hello -

>
> > I am a VBA rookie and am trying to write an Excel Macro which will
> > clear contents of a cell along with any check boxes and option
> > buttons. I got the first part of the macro correct, but when I tried
> > adding additional checkboxes and options to it, it just don't work.

>
> > Here is my code:

>
> > Private Sub CommandButton1_Click()
> > Dim cell As Range
> > For Each cell In ActiveSheet.UsedRange
> > If cell.Locked = False Then cell.MergeArea.ClearContents
> > If OptionButton1.Value = 0 Then OptionButton1.ClearContents
> > If CheckBox1.Value = 0 Then CheckBox1.ClearContents
> > Next
> > End Sub

>
> > Thanks for any help someone can provide.
> > Dan

>
> --
>
> Dave Peterson- Hide quoted text -
>
> - Show quoted text -


Perfect!!! Thanks so much for the help Dave.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Clearing All Checkboxes --Possible? Brian Microsoft Access 4 6th Apr 2008 06:06 AM
Clearing Checkboxes =?Utf-8?B?VGVyaQ==?= Microsoft Access Forms 8 24th May 2006 10:52 PM
Clearing Checkboxes? Jim Microsoft Access Form Coding 4 5th May 2006 05:57 PM
Clearing checkboxes Pic Microsoft Access 2 2nd May 2005 07:50 PM
Clearing Checkboxes =?Utf-8?B?SmFpbWUgQW5kZXJzZW4=?= Microsoft Excel Misc 1 30th Dec 2003 07:18 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:03 PM.