#1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 6
Default Check Box

How do I set a check box to change the background color of a range of cells?

Thank you,

Brian
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 74
Default Check Box

attach the check box to this macro

Sub Changebg()
Range("A1:A10").Select
With Selection.Interior
.ColorIndex = 6 'yellow
.Pattern = xlSolid
End With
Sheets("Sheet1").Select
End Sub


--
If this reply was helpful, please indicate that your question has been
answered to help others find anwsers to similar questions.

www.silverbirddesigns.com

Fighting Texas Aggie Class of 2009


"Brian Smith" wrote:

How do I set a check box to change the background color of a range of cells?

Thank you,

Brian

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 638
Default Check Box

Texas Aggie, selections such as that are considered bad coding
practice unless absolutely necessary. Also, that code will always do
the same thing, regardless of if the checkbox is checked or not.
Should use something like this (assuming the checkbox was added from
the Forms toolbar).
Sub CheckBox1_Click()
Dim colorRange As Range, chkBox As Shape
Set colorRange = ActiveSheet.Range("A2:A5")
For Each chkBox In ActiveSheet.Shapes
If chkBox.Name = "Check Box 1" Then
If ActiveSheet.CheckBoxes(chkBox.Name) _
.Value = 1 Then
colorRange.Interior.ColorIndex = 36
Else
colorRange.Interior.ColorIndex = xlNone
End If
Exit For
End If
Next
Set colorRange = Nothing
End Sub

Texas Aggie wrote:
attach the check box to this macro

Sub Changebg()
Range("A1:A10").Select
With Selection.Interior
.ColorIndex = 6 'yellow
.Pattern = xlSolid
End With
Sheets("Sheet1").Select
End Sub


--
If this reply was helpful, please indicate that your question has been
answered to help others find anwsers to similar questions.

www.silverbirddesigns.com

Fighting Texas Aggie Class of 2009


"Brian Smith" wrote:

How do I set a check box to change the background color of a range of cells?

Thank you,

Brian


  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 74
Default Check Box

JW, hows the weather up there in your chair.
  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 638
Default Check Box

A simpler way:
Sub CheckBox1_Click()
Dim colorRange As Range, chkBoxName As String
chkBoxName = "Check Box 1"
Set colorRange = ActiveSheet.Range("A2:A5")
For Each CheckBox In ActiveSheet.CheckBoxes
If CheckBox.Name = chkBoxName Then
If CheckBox.Value = 1 Then
colorRange.Interior.ColorIndex = 36
Else
colorRange.Interior.ColorIndex = xlNone
End If
Exit For
End If
Next CheckBox
Set colorRange = Nothing
End Sub

JW wrote:
Texas Aggie, selections such as that are considered bad coding
practice unless absolutely necessary. Also, that code will always do
the same thing, regardless of if the checkbox is checked or not.
Should use something like this (assuming the checkbox was added from
the Forms toolbar).
Sub CheckBox1_Click()
Dim colorRange As Range, chkBox As Shape
Set colorRange = ActiveSheet.Range("A2:A5")
For Each chkBox In ActiveSheet.Shapes
If chkBox.Name = "Check Box 1" Then
If ActiveSheet.CheckBoxes(chkBox.Name) _
.Value = 1 Then
colorRange.Interior.ColorIndex = 36
Else
colorRange.Interior.ColorIndex = xlNone
End If
Exit For
End If
Next
Set colorRange = Nothing
End Sub

Texas Aggie wrote:
attach the check box to this macro

Sub Changebg()
Range("A1:A10").Select
With Selection.Interior
.ColorIndex = 6 'yellow
.Pattern = xlSolid
End With
Sheets("Sheet1").Select
End Sub


--
If this reply was helpful, please indicate that your question has been
answered to help others find anwsers to similar questions.

www.silverbirddesigns.com

Fighting Texas Aggie Class of 2009


"Brian Smith" wrote:

How do I set a check box to change the background color of a range of cells?

Thank you,

Brian




  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 638
Default Check Box

Now what exactly is that supposed to mean? I wasn't trying to step on
any toes or ruffle any feathers, but I apparently I did a poor job at
that. We are all on these news groups to learn and to share. Time to
grow up.

Regards,
-Jeff-

Texas Aggie wrote:
JW, hows the weather up there in your chair.


  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 74
Default Check Box

Maybe you should take some of your own advice.
  #8   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 638
Default Check Box

Now that's funny. I have been critiqued several times on this
newsgroup since joining a while back. Never took any of it to heart.
I took it as people trying to help me grow and improve my coding. If
you will go back and read my original response, there is nothing
malicious or harmful in anything that I said.

All that being said, I'm done. To the OP, I hope that you got your
question answered.

Texas Aggie wrote:
Maybe you should take some of your own advice.


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
Increase size of a Forms Check Box (click on to enter check mark) 718Satoshi Excel Discussion (Misc queries) 0 August 17th 07 01:52 AM
Check if Conditional Format is True or False / Check cell Color Kevin McCartney Excel Worksheet Functions 5 June 29th 07 11:12 AM
Enable check box in protected sheet + group check boxes Dexxterr Excel Discussion (Misc queries) 4 August 2nd 06 12:00 PM
... Can I set Spell Check to automatically check my spelling ... Dr. Darrell Setting up and Configuration of Excel 0 March 21st 06 08:26 PM
How do I check/uncheck ten or odd Checkboxes by click on one check Ken Vo Excel Discussion (Misc queries) 5 January 4th 06 11:10 PM


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