Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
dan dan is offline
external usenet poster
 
Posts: 41
Default clearing cells and checkboxes **ROOKIE HERE**

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default clearing cells and checkboxes **ROOKIE HERE**

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
  #3   Report Post  
Posted to microsoft.public.excel.programming
dan dan is offline
external usenet poster
 
Posts: 41
Default clearing cells and checkboxes **ROOKIE HERE**

On Feb 19, 5:05 pm, Dave Peterson 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
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
Clearing cells without clearing formulas marsjune68 Excel Discussion (Misc queries) 2 April 10th 09 07:39 PM
Clearing cells [email protected] Excel Programming 1 January 4th 06 09:48 PM
Array for clearing checkboxes Richard Excel Programming 6 August 12th 05 08:37 AM
Excel VBA Problem - Clearing multiple checkboxes rott[_7_] Excel Programming 2 May 18th 04 09:09 PM
Clearing cells hal Excel Programming 3 August 8th 03 04:01 PM


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