PC Review


Reply
Thread Tools Rate Thread

CheckBox code

 
 
Khalil Handal
Guest
Posts: n/a
 
      19th Jun 2007
Hello to everybody,
I have a sheet for showing a certificate of marks. Sometimes Ithe sum of the
marks need to be shown when printing the certificate, and sometime I n don't
need to see the sum.
I have a checkBox named chekcbox1 on the sheet. What I need is a VBA code so
that when the box is checked to hide the contents of the range C34:E34 which
containes the sum of the marks.
PS. by "hiding" I mean "not to be seen. (maybe changing their color to
white!!)
Can anyone help in writing the code for me?


 
Reply With Quote
 
 
 
 
=?Utf-8?B?RlN0MQ==?=
Guest
Posts: n/a
 
      19th Jun 2007
hi
Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then
Range("C34:E34").Font.Color = RGB(255, 255, 255) ' white
Else
Range("C34:E34").Font.Color = RGB(0, 0, 0) 'black
End If
End Sub

regards
FSt1

"Khalil Handal" wrote:

> Hello to everybody,
> I have a sheet for showing a certificate of marks. Sometimes Ithe sum of the
> marks need to be shown when printing the certificate, and sometime I n don't
> need to see the sum.
> I have a checkBox named chekcbox1 on the sheet. What I need is a VBA code so
> that when the box is checked to hide the contents of the range C34:E34 which
> containes the sum of the marks.
> PS. by "hiding" I mean "not to be seen. (maybe changing their color to
> white!!)
> Can anyone help in writing the code for me?
>
>
>

 
Reply With Quote
 
Khalil Handal
Guest
Posts: n/a
 
      19th Jun 2007
Thanks.It worked well

"FSt1" <(E-Mail Removed)> wrote in message
news:21622319-45AD-4D69-B411-(E-Mail Removed)...
> hi
> Private Sub CheckBox1_Click()
> If CheckBox1.Value = True Then
> Range("C34:E34").Font.Color = RGB(255, 255, 255) ' white
> Else
> Range("C34:E34").Font.Color = RGB(0, 0, 0) 'black
> End If
> End Sub
>
> regards
> FSt1
>
> "Khalil Handal" wrote:
>
>> Hello to everybody,
>> I have a sheet for showing a certificate of marks. Sometimes Ithe sum of
>> the
>> marks need to be shown when printing the certificate, and sometime I n
>> don't
>> need to see the sum.
>> I have a checkBox named chekcbox1 on the sheet. What I need is a VBA code
>> so
>> that when the box is checked to hide the contents of the range C34:E34
>> which
>> containes the sum of the marks.
>> PS. by "hiding" I mean "not to be seen. (maybe changing their color to
>> white!!)
>> Can anyone help in writing the code for me?
>>
>>
>>



 
Reply With Quote
 
Khalil Handal
Guest
Posts: n/a
 
      19th Jun 2007
Hi,
My sheet is protected and the cells are protected.
It does not work in this case what should I do????


"FSt1" <(E-Mail Removed)> wrote in message
news:21622319-45AD-4D69-B411-(E-Mail Removed)...
> hi
> Private Sub CheckBox1_Click()
> If CheckBox1.Value = True Then
> Range("C34:E34").Font.Color = RGB(255, 255, 255) ' white
> Else
> Range("C34:E34").Font.Color = RGB(0, 0, 0) 'black
> End If
> End Sub
>
> regards
> FSt1
>
> "Khalil Handal" wrote:
>
>> Hello to everybody,
>> I have a sheet for showing a certificate of marks. Sometimes Ithe sum of
>> the
>> marks need to be shown when printing the certificate, and sometime I n
>> don't
>> need to see the sum.
>> I have a checkBox named chekcbox1 on the sheet. What I need is a VBA code
>> so
>> that when the box is checked to hide the contents of the range C34:E34
>> which
>> containes the sum of the marks.
>> PS. by "hiding" I mean "not to be seen. (maybe changing their color to
>> white!!)
>> Can anyone help in writing the code for me?
>>
>>
>>



 
Reply With Quote
 
Gord Dibben
Guest
Posts: n/a
 
      19th Jun 2007
Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then
ActiveSheet.UnProtect
Range("C34:E34").Font.Color = RGB(255, 255, 255) ' white
Else
Range("C34:E34").Font.Color = RGB(0, 0, 0) 'black
End If
ActiveSheet.Protect
End Sub


Gord Dibben MS Excel MVP

On Tue, 19 Jun 2007 16:52:48 +0300, "Khalil Handal" <(E-Mail Removed)> wrote:

>Hi,
>My sheet is protected and the cells are protected.
>It does not work in this case what should I do????
>
>
>"FSt1" <(E-Mail Removed)> wrote in message
>news:21622319-45AD-4D69-B411-(E-Mail Removed)...
>> hi
>> Private Sub CheckBox1_Click()
>> If CheckBox1.Value = True Then
>> Range("C34:E34").Font.Color = RGB(255, 255, 255) ' white
>> Else
>> Range("C34:E34").Font.Color = RGB(0, 0, 0) 'black
>> End If
>> End Sub
>>
>> regards
>> FSt1
>>
>> "Khalil Handal" wrote:
>>
>>> Hello to everybody,
>>> I have a sheet for showing a certificate of marks. Sometimes Ithe sum of
>>> the
>>> marks need to be shown when printing the certificate, and sometime I n
>>> don't
>>> need to see the sum.
>>> I have a checkBox named chekcbox1 on the sheet. What I need is a VBA code
>>> so
>>> that when the box is checked to hide the contents of the range C34:E34
>>> which
>>> containes the sum of the marks.
>>> PS. by "hiding" I mean "not to be seen. (maybe changing their color to
>>> white!!)
>>> Can anyone help in writing the code for me?
>>>
>>>
>>>

>


 
Reply With Quote
 
Khalil Handal
Guest
Posts: n/a
 
      19th Jun 2007
Hi,
When I clicked the box the first time it worked fine.
Then I clicked it again (a second time) and had the following error message:
Unable to set the color property of the font class
any ideas!!!!


"Gord Dibben" <gorddibbATshawDOTca> wrote in message
news(E-Mail Removed)...
> Private Sub CheckBox1_Click()
> If CheckBox1.Value = True Then
> ActiveSheet.UnProtect
> Range("C34:E34").Font.Color = RGB(255, 255, 255) ' white
> Else
> Range("C34:E34").Font.Color = RGB(0, 0, 0) 'black
> End If
> ActiveSheet.Protect
> End Sub
>
>
> Gord Dibben MS Excel MVP
>
> On Tue, 19 Jun 2007 16:52:48 +0300, "Khalil Handal" <(E-Mail Removed)>
> wrote:
>
>>Hi,
>>My sheet is protected and the cells are protected.
>>It does not work in this case what should I do????
>>
>>
>>"FSt1" <(E-Mail Removed)> wrote in message
>>news:21622319-45AD-4D69-B411-(E-Mail Removed)...
>>> hi
>>> Private Sub CheckBox1_Click()
>>> If CheckBox1.Value = True Then
>>> Range("C34:E34").Font.Color = RGB(255, 255, 255) ' white
>>> Else
>>> Range("C34:E34").Font.Color = RGB(0, 0, 0) 'black
>>> End If
>>> End Sub
>>>
>>> regards
>>> FSt1
>>>
>>> "Khalil Handal" wrote:
>>>
>>>> Hello to everybody,
>>>> I have a sheet for showing a certificate of marks. Sometimes Ithe sum
>>>> of
>>>> the
>>>> marks need to be shown when printing the certificate, and sometime I n
>>>> don't
>>>> need to see the sum.
>>>> I have a checkBox named chekcbox1 on the sheet. What I need is a VBA
>>>> code
>>>> so
>>>> that when the box is checked to hide the contents of the range C34:E34
>>>> which
>>>> containes the sum of the marks.
>>>> PS. by "hiding" I mean "not to be seen. (maybe changing their color to
>>>> white!!)
>>>> Can anyone help in writing the code for me?
>>>>
>>>>
>>>>

>>

>



 
Reply With Quote
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      19th Jun 2007
Even more descriptive (in my opinion) are these (which use two of the many,
many predefined constants in VBA)...

> Range("C34:E34").Font.Color = RGB(255, 255, 255) ' white


Range("C34:E34").Font.Color = vbWhite

> Range("C34:E34").Font.Color = RGB(0, 0, 0) 'black


Range("C34:E34").Font.Color = vbBlack


Rick

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      19th Jun 2007
Moving the .unprotect line helped:

Option Explicit
Private Sub CheckBox1_Click()
Me.Unprotect
If CheckBox1.Value = True Then
Me.Range("C34:E34").Font.Color = RGB(255, 255, 255) ' white
Else
Me.Range("C34:E34").Font.Color = RGB(0, 0, 0) 'black
End If
Me.Protect
End Sub

The me keyword refers to the worksheet that owns the code.



Khalil Handal wrote:
>
> Hi,
> When I clicked the box the first time it worked fine.
> Then I clicked it again (a second time) and had the following error message:
> Unable to set the color property of the font class
> any ideas!!!!
>
> "Gord Dibben" <gorddibbATshawDOTca> wrote in message
> news(E-Mail Removed)...
> > Private Sub CheckBox1_Click()
> > If CheckBox1.Value = True Then
> > ActiveSheet.UnProtect
> > Range("C34:E34").Font.Color = RGB(255, 255, 255) ' white
> > Else
> > Range("C34:E34").Font.Color = RGB(0, 0, 0) 'black
> > End If
> > ActiveSheet.Protect
> > End Sub
> >
> >
> > Gord Dibben MS Excel MVP
> >
> > On Tue, 19 Jun 2007 16:52:48 +0300, "Khalil Handal" <(E-Mail Removed)>
> > wrote:
> >
> >>Hi,
> >>My sheet is protected and the cells are protected.
> >>It does not work in this case what should I do????
> >>
> >>
> >>"FSt1" <(E-Mail Removed)> wrote in message
> >>news:21622319-45AD-4D69-B411-(E-Mail Removed)...
> >>> hi
> >>> Private Sub CheckBox1_Click()
> >>> If CheckBox1.Value = True Then
> >>> Range("C34:E34").Font.Color = RGB(255, 255, 255) ' white
> >>> Else
> >>> Range("C34:E34").Font.Color = RGB(0, 0, 0) 'black
> >>> End If
> >>> End Sub
> >>>
> >>> regards
> >>> FSt1
> >>>
> >>> "Khalil Handal" wrote:
> >>>
> >>>> Hello to everybody,
> >>>> I have a sheet for showing a certificate of marks. Sometimes Ithe sum
> >>>> of
> >>>> the
> >>>> marks need to be shown when printing the certificate, and sometime I n
> >>>> don't
> >>>> need to see the sum.
> >>>> I have a checkBox named chekcbox1 on the sheet. What I need is a VBA
> >>>> code
> >>>> so
> >>>> that when the box is checked to hide the contents of the range C34:E34
> >>>> which
> >>>> containes the sum of the marks.
> >>>> PS. by "hiding" I mean "not to be seen. (maybe changing their color to
> >>>> white!!)
> >>>> Can anyone help in writing the code for me?
> >>>>
> >>>>
> >>>>
> >>

> >


--

Dave Peterson
 
Reply With Quote
 
Khalil Handal
Guest
Posts: n/a
 
      19th Jun 2007
Thanks a lot to all of you.
It worked just fine

"Dave Peterson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Moving the .unprotect line helped:
>
> Option Explicit
> Private Sub CheckBox1_Click()
> Me.Unprotect
> If CheckBox1.Value = True Then
> Me.Range("C34:E34").Font.Color = RGB(255, 255, 255) ' white
> Else
> Me.Range("C34:E34").Font.Color = RGB(0, 0, 0) 'black
> End If
> Me.Protect
> End Sub
>
> The me keyword refers to the worksheet that owns the code.
>
>
>
> Khalil Handal wrote:
>>
>> Hi,
>> When I clicked the box the first time it worked fine.
>> Then I clicked it again (a second time) and had the following error
>> message:
>> Unable to set the color property of the font class
>> any ideas!!!!
>>
>> "Gord Dibben" <gorddibbATshawDOTca> wrote in message
>> news(E-Mail Removed)...
>> > Private Sub CheckBox1_Click()
>> > If CheckBox1.Value = True Then
>> > ActiveSheet.UnProtect
>> > Range("C34:E34").Font.Color = RGB(255, 255, 255) ' white
>> > Else
>> > Range("C34:E34").Font.Color = RGB(0, 0, 0) 'black
>> > End If
>> > ActiveSheet.Protect
>> > End Sub
>> >
>> >
>> > Gord Dibben MS Excel MVP
>> >
>> > On Tue, 19 Jun 2007 16:52:48 +0300, "Khalil Handal"
>> > <(E-Mail Removed)>
>> > wrote:
>> >
>> >>Hi,
>> >>My sheet is protected and the cells are protected.
>> >>It does not work in this case what should I do????
>> >>
>> >>
>> >>"FSt1" <(E-Mail Removed)> wrote in message
>> >>news:21622319-45AD-4D69-B411-(E-Mail Removed)...
>> >>> hi
>> >>> Private Sub CheckBox1_Click()
>> >>> If CheckBox1.Value = True Then
>> >>> Range("C34:E34").Font.Color = RGB(255, 255, 255) ' white
>> >>> Else
>> >>> Range("C34:E34").Font.Color = RGB(0, 0, 0) 'black
>> >>> End If
>> >>> End Sub
>> >>>
>> >>> regards
>> >>> FSt1
>> >>>
>> >>> "Khalil Handal" wrote:
>> >>>
>> >>>> Hello to everybody,
>> >>>> I have a sheet for showing a certificate of marks. Sometimes Ithe
>> >>>> sum
>> >>>> of
>> >>>> the
>> >>>> marks need to be shown when printing the certificate, and sometime I
>> >>>> n
>> >>>> don't
>> >>>> need to see the sum.
>> >>>> I have a checkBox named chekcbox1 on the sheet. What I need is a VBA
>> >>>> code
>> >>>> so
>> >>>> that when the box is checked to hide the contents of the range
>> >>>> C34:E34
>> >>>> which
>> >>>> containes the sum of the marks.
>> >>>> PS. by "hiding" I mean "not to be seen. (maybe changing their color
>> >>>> to
>> >>>> white!!)
>> >>>> Can anyone help in writing the code for me?
>> >>>>
>> >>>>
>> >>>>
>> >>
>> >

>
> --
>
> Dave Peterson



 
Reply With Quote
 
Khalil Handal
Guest
Posts: n/a
 
      19th Jun 2007
Yours also worked well; it gave the same result.
thanks

"Rick Rothstein (MVP - VB)" <(E-Mail Removed)> wrote in
message news:%(E-Mail Removed)...
> Even more descriptive (in my opinion) are these (which use two of the
> many, many predefined constants in VBA)...
>
>> Range("C34:E34").Font.Color = RGB(255, 255, 255) ' white

>
> Range("C34:E34").Font.Color = vbWhite
>
>> Range("C34:E34").Font.Color = RGB(0, 0, 0) 'black

>
> Range("C34:E34").Font.Color = vbBlack
>
>
> Rick



 
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
Color code Yes/No checkbox and text dependent on checkbox =?Utf-8?B?VG90YWxseUNvbmZ1c2Vk?= Microsoft Access Forms 2 16th Feb 2006 07:38 PM
help in checkbox code Soniya Microsoft Excel Programming 1 24th Apr 2005 01:49 PM
VBA to run all checkbox code Todd Microsoft Excel Misc 1 15th Sep 2004 12:10 AM
Master-Detail Datagrid -checkbox (once tick the checkbox, all the child checkbox is ticked) Agnes Microsoft VB .NET 0 16th Aug 2004 11:23 AM
checkbox code Thrava Microsoft Excel Misc 6 5th May 2004 11:55 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:07 PM.