PC Review


Reply
Thread Tools Rate Thread

Change background based on value in another column

 
 
MM User
Guest
Posts: n/a
 
      16th Dec 2008
Hi,

I have in column A options: a,b,c or d

depending on what is chosen is it possible change the background color of
the relevant row in B and C?

i.e. if a3 = a then b3 & d3 background is red or
if a3 = b then b3 & d3 background is green etc

If possible is it possible to do this automatically i.e. not run a macro
just on a cell change in A?

Thanks!
 
Reply With Quote
 
 
 
 
Brotha Lee
Guest
Posts: n/a
 
      16th Dec 2008
MM,

You could use regular Excel functionality like conditional formatting (under
format menu), however if you desire a code use the following. You should
paste it somewhere in the appropriate sheet object
Private Sub Worksheet_Change(ByVal Target As Range)
'Use Lcase(Target) if it should not be case sensitive
Select Case Target
Case Is = "a"
Cells(Target.Row, 2).Interior.Color = vbRed
Cells(Target.Row, 3).Interior.Color = vbRed
Case Is = "b"
Cells(Target.Row, 2).Interior.Color = vbGreen
Cells(Target.Row, 3).Interior.Color = vbGreen
Case Else
'No appropriate entry, clear color
Cells(Target.Row, 2).Interior.ColorIndex = xlNone
Cells(Target.Row, 3).Interior.ColorIndex = xlNone
End Select

End Sub

HTH
Brotha lee

"MM User" wrote:

> Hi,
>
> I have in column A options: a,b,c or d
>
> depending on what is chosen is it possible change the background color of
> the relevant row in B and C?
>
> i.e. if a3 = a then b3 & d3 background is red or
> if a3 = b then b3 & d3 background is green etc
>
> If possible is it possible to do this automatically i.e. not run a macro
> just on a cell change in A?
>
> Thanks!
>

 
Reply With Quote
 
Gord Dibben
Guest
Posts: n/a
 
      16th Dec 2008
Private Sub Worksheet_Change(ByVal Target As Range)
Dim R As Range
Dim iColor As Long
Set R = Range("A1:A100")
If Intersect(Target, R) Is Nothing Or Target.Count > 1 Then Exit Sub
Vals = Array("A", "B", "C", "D")
Nums = Array(8, 9, 6, 3)
For i = LBound(Vals) To UBound(Vals)
If UCase(Target.Value) = Vals(i) Then iColor = Nums(i)
Next
With Target
.Offset(0, 1).Interior.ColorIndex = iColor
.Offset(0, 3).Interior.ColorIndex = iColor
End With
End Sub

Note: you could do this with Conditional Formatting.........default color
for a and three others for b, c, d

If using Excel 2007 you have many more conditions.


Gord Dibben MS Excel MVP

On Tue, 16 Dec 2008 20:50:25 -0000, "MM User" <(E-Mail Removed)> wrote:

>Hi,
>
>I have in column A options: a,b,c or d
>
>depending on what is chosen is it possible change the background color of
>the relevant row in B and C?
>
>i.e. if a3 = a then b3 & d3 background is red or
>if a3 = b then b3 & d3 background is green etc
>
>If possible is it possible to do this automatically i.e. not run a macro
>just on a cell change in A?
>
>Thanks!


 
Reply With Quote
 
Excel User
Guest
Posts: n/a
 
      16th Dec 2008
Thanks Brotha,

I think I've got it!

Regards



"Brotha Lee" <(E-Mail Removed)> wrote in message
news:4431D48A-9C8D-422C-8F77-(E-Mail Removed)...
> MM,
>
> You could use regular Excel functionality like conditional formatting
> (under
> format menu), however if you desire a code use the following. You should
> paste it somewhere in the appropriate sheet object
> Private Sub Worksheet_Change(ByVal Target As Range)
> 'Use Lcase(Target) if it should not be case sensitive
> Select Case Target
> Case Is = "a"
> Cells(Target.Row, 2).Interior.Color = vbRed
> Cells(Target.Row, 3).Interior.Color = vbRed
> Case Is = "b"
> Cells(Target.Row, 2).Interior.Color = vbGreen
> Cells(Target.Row, 3).Interior.Color = vbGreen
> Case Else
> 'No appropriate entry, clear color
> Cells(Target.Row, 2).Interior.ColorIndex = xlNone
> Cells(Target.Row, 3).Interior.ColorIndex = xlNone
> End Select
>
> End Sub
>
> HTH
> Brotha lee
>
> "MM User" wrote:
>
>> Hi,
>>
>> I have in column A options: a,b,c or d
>>
>> depending on what is chosen is it possible change the background color of
>> the relevant row in B and C?
>>
>> i.e. if a3 = a then b3 & d3 background is red or
>> if a3 = b then b3 & d3 background is green etc
>>
>> If possible is it possible to do this automatically i.e. not run a macro
>> just on a cell change in A?
>>
>> Thanks!
>>

 
Reply With Quote
 
MM User
Guest
Posts: n/a
 
      18th Dec 2008
Thanks Gord,

That great!


"Gord Dibben" <gorddibbATshawDOTca> wrote in message
news:(E-Mail Removed)...
> Private Sub Worksheet_Change(ByVal Target As Range)
> Dim R As Range
> Dim iColor As Long
> Set R = Range("A1:A100")
> If Intersect(Target, R) Is Nothing Or Target.Count > 1 Then Exit Sub
> Vals = Array("A", "B", "C", "D")
> Nums = Array(8, 9, 6, 3)
> For i = LBound(Vals) To UBound(Vals)
> If UCase(Target.Value) = Vals(i) Then iColor = Nums(i)
> Next
> With Target
> .Offset(0, 1).Interior.ColorIndex = iColor
> .Offset(0, 3).Interior.ColorIndex = iColor
> End With
> End Sub
>
> Note: you could do this with Conditional Formatting.........default color
> for a and three others for b, c, d
>
> If using Excel 2007 you have many more conditions.
>
>
> Gord Dibben MS Excel MVP
>
> On Tue, 16 Dec 2008 20:50:25 -0000, "MM User" <(E-Mail Removed)>
> wrote:
>
>>Hi,
>>
>>I have in column A options: a,b,c or d
>>
>>depending on what is chosen is it possible change the background color of
>>the relevant row in B and C?
>>
>>i.e. if a3 = a then b3 & d3 background is red or
>>if a3 = b then b3 & d3 background is green etc
>>
>>If possible is it possible to do this automatically i.e. not run a macro
>>just on a cell change in A?
>>
>>Thanks!

>


 
Reply With Quote
 
Toypon
Guest
Posts: n/a
 
      16th Jan 2009
Thank's Brotha Lee!

I have another function I want to add to this if anyone could help me.
I use a locked sheet with some unlocked cells and based on the value in A2
the cell B2, C2 aso should change between locked and unlocked along with the
background.

How do I do this? I Use Brotha Lee's example of changeing background.

Thanks in advance!

"Brotha Lee" wrote:

> MM,
>
> You could use regular Excel functionality like conditional formatting (under
> format menu), however if you desire a code use the following. You should
> paste it somewhere in the appropriate sheet object
> Private Sub Worksheet_Change(ByVal Target As Range)
> 'Use Lcase(Target) if it should not be case sensitive
> Select Case Target
> Case Is = "a"
> Cells(Target.Row, 2).Interior.Color = vbRed
> Cells(Target.Row, 3).Interior.Color = vbRed
> Case Is = "b"
> Cells(Target.Row, 2).Interior.Color = vbGreen
> Cells(Target.Row, 3).Interior.Color = vbGreen
> Case Else
> 'No appropriate entry, clear color
> Cells(Target.Row, 2).Interior.ColorIndex = xlNone
> Cells(Target.Row, 3).Interior.ColorIndex = xlNone
> End Select
>
> End Sub
>
> HTH
> Brotha lee
>
> "MM User" wrote:
>
> > Hi,
> >
> > I have in column A options: a,b,c or d
> >
> > depending on what is chosen is it possible change the background color of
> > the relevant row in B and C?
> >
> > i.e. if a3 = a then b3 & d3 background is red or
> > if a3 = b then b3 & d3 background is green etc
> >
> > If possible is it possible to do this automatically i.e. not run a macro
> > just on a cell change in A?
> >
> > Thanks!
> >

 
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
Can I change background colors based on criteria from another cel. WavMaster Microsoft Excel Misc 2 8th Feb 2009 07:19 PM
change background color based on range value DanL Microsoft Excel New Users 2 6th Feb 2009 09:35 PM
Change background color based on value in column A JT Innovations Microsoft Excel Misc 4 23rd Jan 2009 07:14 PM
datagridview row background color based on column value in data va =?Utf-8?B?R3JlZyBMYXJzZW4=?= Microsoft C# .NET 1 27th Dec 2006 10:03 AM
Can I Change color of background based on the date wojo Microsoft Access 7 17th Jul 2005 10:48 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:11 AM.