Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 98
Default Code question for clearing a command checkbox.

Hi I have a command checkbox, such when its checked, it clears and unables
two form option buttons as below,

Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then

ActiveSheet.OptionButtons("Option Button 149").Enabled = False
ActiveSheet.OptionButtons("Option Button 149").Value = xlunchecked
ActiveSheet.OptionButtons("Option Button 150").Enabled = False
ActiveSheet.OptionButtons("Option Button 150").Value = xlunchecked

Else

ActiveSheet.OptionButtons("Option Button 149").Enabled = True
ActiveSheet.OptionButtons("Option Button 150").Enabled = True

End if
End Sub

I have on another sheet a button that when pressed clears the above option
buttons and checkbox.

Private Sub clearsheet2_Click()

Sheets("sheet2").Unprotect password:=("password")
Worksheets("sheet2").OptionButtons.Value = xlOff
Worksheets("sheet2").CheckBox1.Value = xloff
Sheets("sheet2").Protect password:=("password")

End Sub.


When this runs checkbox1 shades out but the tick is still there, I then
changed the line;

Worksheets("sheet2").CheckBox1.Value = xloff

to

Worksheets("sheet2").CheckBox1.Value = false

When I run now I get an error after the else in the code at the top.

How can I amend this to stop the error and to have the checkbox unchecked?

--
This post was created using recycled electrons!
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10,593
Default Code question for clearing a command checkbox.

Couple of points.

Are the optionbuttons from the forms toolbar?

You can't set/unset two option buttons, setting one unsets the other.

This works

Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then

ActiveSheet.OptionButtons("Option Button 149").Value = 1

Else

ActiveSheet.OptionButtons("Option Button 150").Value = 1

End If
End Sub


--
HTH

Bob Phillips

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

"Newbeetle" wrote in message
...
Hi I have a command checkbox, such when its checked, it clears and unables
two form option buttons as below,

Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then

ActiveSheet.OptionButtons("Option Button 149").Enabled = False
ActiveSheet.OptionButtons("Option Button 149").Value = xlunchecked
ActiveSheet.OptionButtons("Option Button 150").Enabled = False
ActiveSheet.OptionButtons("Option Button 150").Value = xlunchecked

Else

ActiveSheet.OptionButtons("Option Button 149").Enabled = True
ActiveSheet.OptionButtons("Option Button 150").Enabled = True

End if
End Sub

I have on another sheet a button that when pressed clears the above option
buttons and checkbox.

Private Sub clearsheet2_Click()

Sheets("sheet2").Unprotect password:=("password")
Worksheets("sheet2").OptionButtons.Value = xlOff
Worksheets("sheet2").CheckBox1.Value = xloff
Sheets("sheet2").Protect password:=("password")

End Sub.


When this runs checkbox1 shades out but the tick is still there, I then
changed the line;

Worksheets("sheet2").CheckBox1.Value = xloff

to

Worksheets("sheet2").CheckBox1.Value = false

When I run now I get an error after the else in the code at the top.

How can I amend this to stop the error and to have the checkbox

unchecked?

--
This post was created using recycled electrons!



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 98
Default Code question for clearing a command checkbox.

Hi Bob,

Thats interesting I didn't know you could use 0 and 1's saves me typing True
and False all the time.

I will still have the same problem where if I set the line from,

Worksheets("sheet2").CheckBox1.Value = xloff

to

Worksheets("sheet2").CheckBox1.Value = False

or

Worksheets("sheet2").CheckBox1.Value = False

The control checkbox1 is unchecked but I get a run error on the else
statement, when using the macro to clear all the form option buttons.

Any thoughts?
--
This post was created using recycled electrons!


"Bob Phillips" wrote:

Couple of points.

Are the optionbuttons from the forms toolbar?

You can't set/unset two option buttons, setting one unsets the other.

This works

Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then

ActiveSheet.OptionButtons("Option Button 149").Value = 1

Else

ActiveSheet.OptionButtons("Option Button 150").Value = 1

End If
End Sub




  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 98
Default Code question for clearing a command checkbox.

I'm please to say some of the stuff your guys have taught me is finally
sticking in the grey cells, and I've managed to answer my question,

I altered the code below,

ActiveSheet.OptionButtons("Option Button 149").Enabled = False
ActiveSheet.OptionButtons("Option Button 149").Value = xlunchecked


to read

Worksheets ("Sheetname").OptionButtons("Option Button 149").Enabled = False
Worksheets ("Sheetname").OptionButtons("Option Button 149").Value =
xlunchecked

The problem was created due to the command button being used to clear the
option buttons was on another page, well thats my theory lol.

--
This post was created using recycled electrons!


  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10,593
Default Code question for clearing a command checkbox.

Excel does not have a constant xlunchecked!

--
HTH

Bob Phillips

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

"Newbeetle" wrote in message
...
I'm please to say some of the stuff your guys have taught me is finally
sticking in the grey cells, and I've managed to answer my question,

I altered the code below,

ActiveSheet.OptionButtons("Option Button 149").Enabled = False
ActiveSheet.OptionButtons("Option Button 149").Value = xlunchecked


to read

Worksheets ("Sheetname").OptionButtons("Option Button 149").Enabled =

False
Worksheets ("Sheetname").OptionButtons("Option Button 149").Value =
xlunchecked

The problem was created due to the command button being used to clear the
option buttons was on another page, well thats my theory lol.

--
This post was created using recycled electrons!






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
a tough question - calculating a number out of an alphanumeric code usingexcel Excel Discussion (Misc queries) 2 August 3rd 06 06:07 PM
Need to Improve Code Copying/Pasting Between Workbooks David Excel Discussion (Misc queries) 1 January 6th 06 03:56 AM
Change case...help please Terry Excel Worksheet Functions 14 October 2nd 05 12:29 PM
Macro for changing text to Proper Case JPriest Excel Worksheet Functions 3 August 8th 05 09:31 PM
syntax question - cell references in VB code needyourhelp New Users to Excel 1 March 2nd 05 08:52 PM


All times are GMT +1. The time now is 04:35 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"