Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 2
Default how to change a cell color based on its content using macro?

Hi, I want to automatically change the color of a cell when a user select a
color from a drop-down list. For example: user selects 'green' would change
the color of the same cell to green.
Appreicate any help to implement this.
Thanks

  #2   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 10,593
Default how to change a cell color based on its content using macro?


'-----------------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
'-----------------------------------------------------------------
Const WS_RANGE As String = "H1" '<=== change to suit

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
Select Case .Value
Case "red": .Interior.ColorIndex = 3 'red
Case "yellow": .Interior.ColorIndex = 6 'yellow
Case "blue": .Interior.ColorIndex = 5 'blue
Case "green": .Interior.ColorIndex = 10 'green
End Select
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.



--
---
HTH

Bob

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



"Ranger888" wrote in message
...
Hi, I want to automatically change the color of a cell when a user select
a
color from a drop-down list. For example: user selects 'green' would
change
the color of the same cell to green.
Appreicate any help to implement this.
Thanks



  #3   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 2
Default how to change a cell color based on its content using macro?

Hi Bob,
Thanks for taking time to reply, your solution is perfect.
Regards,
Rod

"Bob Phillips" wrote:


'-----------------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
'-----------------------------------------------------------------
Const WS_RANGE As String = "H1" '<=== change to suit

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
Select Case .Value
Case "red": .Interior.ColorIndex = 3 'red
Case "yellow": .Interior.ColorIndex = 6 'yellow
Case "blue": .Interior.ColorIndex = 5 'blue
Case "green": .Interior.ColorIndex = 10 'green
End Select
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.



--
---
HTH

Bob

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



"Ranger888" wrote in message
...
Hi, I want to automatically change the color of a cell when a user select
a
color from a drop-down list. For example: user selects 'green' would
change
the color of the same cell to green.
Appreicate any help to implement this.
Thanks




  #4   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 1
Default how to change a cell color based on its content using macro?

Is it possible to use the fill formatting, using an InputBox return,
triggered in sub Worksheet_Change, i.e. not based on the field's content,
but on a users input following the entry of text?

"Bob Phillips" wrote:


'-----------------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
'-----------------------------------------------------------------
Const WS_RANGE As String = "H1" '<=== change to suit

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
Select Case .Value
Case "red": .Interior.ColorIndex = 3 'red
Case "yellow": .Interior.ColorIndex = 6 'yellow
Case "blue": .Interior.ColorIndex = 5 'blue
Case "green": .Interior.ColorIndex = 10 'green
End Select
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.



--
---
HTH

Bob

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



"Ranger888" wrote in message
...
Hi, I want to automatically change the color of a cell when a user select
a
color from a drop-down list. For example: user selects 'green' would
change
the color of the same cell to green.
Appreicate any help to implement this.
Thanks




  #5   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 1
Default how to change a cell color based on its content using macro?

I have a similar (I think) question and you seem to know what you're talking
about :)

I teach high school and have a spreadsheet with students' names listed each
time they're sent to the "Behavior Improvement Center" for infractions of
rules or dress code violations. The man in charge of the center wants to
know if there is a way to automatically change the color of the student's
name when it has been input into the spreadsheet more than a certain number
of times, as there are consequences such as suspension, etc. I have been
using Excel for 20 years and am the guru around here, but I can't seem to
figure out a way to do this and don't even know if it's possible.

Any suggestions would be appreciated,

Christienne Moudden



"Bob Phillips" wrote:


'-----------------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
'-----------------------------------------------------------------
Const WS_RANGE As String = "H1" '<=== change to suit

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
Select Case .Value
Case "red": .Interior.ColorIndex = 3 'red
Case "yellow": .Interior.ColorIndex = 6 'yellow
Case "blue": .Interior.ColorIndex = 5 'blue
Case "green": .Interior.ColorIndex = 10 'green
End Select
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.



--
---
HTH

Bob

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



"Ranger888" wrote in message
...
Hi, I want to automatically change the color of a cell when a user select
a
color from a drop-down list. For example: user selects 'green' would
change
the color of the same cell to green.
Appreicate any help to implement this.
Thanks






  #6   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 7,247
Default how to change a cell color based on its content using macro?

Select the cells that you want to format. In this example, we'll
assume that range is A1:A10. With the cells selected, go to the Format
menu and choose Conditional Formatting. In that dialog, change "Cell
Value Is" to "Formula Is" and enter the following formula:

=COUNTIF($A$1:$A$10,A1)=N

Here, change $A$1:$A$10 to the full range of student names (using the
$ characters as shown) and change the A1 (without $ characters) to the
first cell in the list of names. Change the N to the minimum number of
times that a name need appear in the list to cause the formatting to
be applied.

Click the Format menu and choose formatting to be applied if the
student appears in the lists more than N times.

Cordially,
Chip Pearson
Microsoft MVP
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Mon, 15 Dec 2008 10:58:06 -0800, Christienne Moudden <Christienne
wrote:

I have a similar (I think) question and you seem to know what you're talking
about :)

I teach high school and have a spreadsheet with students' names listed each
time they're sent to the "Behavior Improvement Center" for infractions of
rules or dress code violations. The man in charge of the center wants to
know if there is a way to automatically change the color of the student's
name when it has been input into the spreadsheet more than a certain number
of times, as there are consequences such as suspension, etc. I have been
using Excel for 20 years and am the guru around here, but I can't seem to
figure out a way to do this and don't even know if it's possible.

Any suggestions would be appreciated,

Christienne Moudden



"Bob Phillips" wrote:


'-----------------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
'-----------------------------------------------------------------
Const WS_RANGE As String = "H1" '<=== change to suit

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
Select Case .Value
Case "red": .Interior.ColorIndex = 3 'red
Case "yellow": .Interior.ColorIndex = 6 'yellow
Case "blue": .Interior.ColorIndex = 5 'blue
Case "green": .Interior.ColorIndex = 10 'green
End Select
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.



--
---
HTH

Bob

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



"Ranger888" wrote in message
...
Hi, I want to automatically change the color of a cell when a user select
a
color from a drop-down list. For example: user selects 'green' would
change
the color of the same cell to green.
Appreicate any help to implement this.
Thanks




  #7   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 1
Default how to change a cell color based on its content using macro?

Wow -- you're amazing !!! Thank you so much !!!

Christienne

"Ranger888" wrote:

Hi, I want to automatically change the color of a cell when a user select a
color from a drop-down list. For example: user selects 'green' would change
the color of the same cell to green.
Appreicate any help to implement this.
Thanks

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
Excel: Syntax to change cell color based on color of another cell davew18 Excel Worksheet Functions 1 January 4th 07 01:24 PM
how do I change the content of one cell based on another? Barry Excel Discussion (Misc queries) 2 September 3rd 06 10:16 AM
Change the data in one cell based on content of another. Barry Excel Discussion (Misc queries) 2 September 3rd 06 08:26 AM
Change tab color based on a cell value Zenaida Excel Discussion (Misc queries) 14 April 27th 06 10:35 PM
How do I change content of a cell based on date diving1 Excel Worksheet Functions 2 December 19th 04 08:39 PM


All times are GMT +1. The time now is 01:37 AM.

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"