Mourning the loss of our friend, WhitPhil.
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
 
Business Applications
Tag Cloud
access audio black screen blue screen boot bsod connection crash dell desktop driver drivers dvd email error excel firefox hard drive hardware hijackthis internet keyboard laptop malware monitor motherboard network networking outlook problem processor recovery router safe mode screen slow sound spyware tdlwsp.dll trojan upgrade video virus vista vundo windows windows 7 windows vista windows xp wireless
Search
Search for:
Tech Support Guy Forums > Software & Hardware > Business Applications >
Solved: excel checkbox

Tip: Click here to scan for System Errors and Optimize PC performance
[ Sponsored Link ]

 
Thread Tools
scouse13's Avatar
Junior Member with 12 posts.
 
Join Date: Oct 2009
04-Nov-2009, 04:40 AM #1
Solved: excel checkbox
can anyone help please,

i have a few checkboxes on a worksheet and what i would like to do, is when a checkbox is checked, is for a range of cells to change colour, i.e b6:b9, also once i have finished with the worksheet and press a reset button for the cells to revert back to their origional colour.
bomb #21's Avatar
Distinguished Member with 7,166 posts.
 
Join Date: Jul 2005
Location: The void AKA edge of the Fens
Experience: I bent my wookie :(
04-Nov-2009, 10:08 AM #2
Linking the check box to a cell (e.g. B2) will give you TRUE when checked, FALSE when unchecked.

Then use a conditional formatting formula for B6:B9 such as:

=$B$2=TRUE

HTH

(red or blue scouse? )
scouse13's Avatar
Junior Member with 12 posts.
 
Join Date: Oct 2009
04-Nov-2009, 08:02 PM #3
excel checkbox
thankx bomb21
i dont want to use a button to make the changes i want it to happen automattically when the check box ix checked, whats the code and where do i put it
thanks
also stupid as i am, where do u check for the code for colours
Rollin_Again's Avatar
Distinguished Member with 3,730 posts.
 
Join Date: Sep 2003
Location: Atlanta, GA - Planet Earth
Experience: Brilliant When Sober
04-Nov-2009, 08:38 PM #4
The checkbox needs to be added from the Control Toolbox and NOT the Forms Toolbox. Once added you can right click it and choose VIEW CODE. Then just add your code to the change event. Just replace the name of the textbox in line 1 with the actual name of your own checkbox.

Code:
Private Sub CheckBox1_Change()

Range("A1:C1").Interior.ColorIndex = 6

End Sub
Regards,
Rollin
bomb #21's Avatar
Distinguished Member with 7,166 posts.
 
Join Date: Jul 2005
Location: The void AKA edge of the Fens
Experience: I bent my wookie :(
05-Nov-2009, 03:49 AM #5
Quote:
Originally Posted by scouse13
thankx bomb21
i dont want to use a button to make the changes i want it to happen automattically when the check box ix checked, whats the code and where do i put it
thanks
also stupid as i am, where do u check for the code for colours
I don't understand your post.

1. I didn't mention using a button at all.

2. If you use a Control Toolbox checkbox, you don't need any (VBA) code specifically, you just link it to the cells (to colour) using the LinkedCell property. If you use a Forms toolbar checkbox, you don't need any code at all.

3. I guessed that you already have a checkbox on your sheet. You didn't say which type you'd used, so I made the "instructions" basic enough that they'd work for either type (I did test this)

4. Rollin's code (assuming you know how to exit Design Mode) will format A1:C1 with a yellow background when you check the box. But it won't "unformat" when you uncheck the box -- you'd need additional code for that.

HTH
__________________
"Love All The People."
Bill Hicks, 1961 - 1994 -- R.I.P.
Rollin_Again's Avatar
Distinguished Member with 3,730 posts.
 
Join Date: Sep 2003
Location: Atlanta, GA - Planet Earth
Experience: Brilliant When Sober
05-Nov-2009, 06:41 AM #6
Per Bomb's comment above, here is the modified code that includes logic to uncolor the cells when the checkbox is unchecked.

Code:
Private Sub CheckBox1_Change()

Select Case CheckBox1.Value

Case True

Range("A1:C1").Interior.ColorIndex = 6

Case False

Range("A1:C1").Interior.ColorIndex = xlNone

End Select

End Sub
Regards,
Rollin
scouse13's Avatar
Junior Member with 12 posts.
 
Join Date: Oct 2009
05-Nov-2009, 07:28 AM #7
thanks rollin
works a treat, just 2 things, firstly i want to be able use a control button to automatically uncheck all the checkboxes rather than to click each one individually, what would the code be for this to happen? also were can i check what numbers refer to the colours, i have the cells now that are coloured using the drop down colour box, they also have a fill effect, when the checkbox is unchecked i would like the cells to refer back to these settings,
hope u understand my rambling message
thanks scouse
bomb #21's Avatar
Distinguished Member with 7,166 posts.
 
Join Date: Jul 2005
Location: The void AKA edge of the Fens
Experience: I bent my wookie :(
05-Nov-2009, 08:01 AM #8
To automatically uncheck all the checkboxes:

Me.CheckBox1 = False
Me.CheckBox2 = False

and so on. ( http://www.ozgrid.com/forum/showthread.php?t=48933 )

"were can i check what numbers refer to the colours"

Here's one way to create an index:

Sub test()
For Each Cell In Range("A1:A56")
Cell.Interior.ColorIndex = Cell.Row
Cell.Offset(, 1) = Cell.Row
Next Cell
End Sub


HTH
__________________
"Love All The People."
Bill Hicks, 1961 - 1994 -- R.I.P.
Rollin_Again's Avatar
Distinguished Member with 3,730 posts.
 
Join Date: Sep 2003
Location: Atlanta, GA - Planet Earth
Experience: Brilliant When Sober
05-Nov-2009, 09:21 AM #9
Or if you prefer to use a loop you can use the code below.

Code:
Private Sub CommandButton1_Click()

Dim vCheck As Object

For Each vCheck In ActiveSheet.OLEObjects
If TypeName(vCheck.Object) = "CheckBox" Then
vCheck.Object.Value = True
End If
Next vCheck

End Sub
Regards,
Rollin
Reply Bookmark and Share

Smart Search

Find your solution!



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.

Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -5. The time now is 01:05 PM.
Copyright © 1996 - 2009 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.
Powered by Cermak Technologies, Inc.