Search : in
By :

Excel conditional formatting row color

Last answer on Oct 28, 2009 9:30:24 am GMT Katsu, on May 13, 2009 2:53:14 pm BST 
 Report this message to moderators

Hello,
I am trying to get Excel to automatically change the color of a row depending on the entry in column H. I've got some VBA code written up, but I can't seem to get it to work. Am I making a programming mistake, or is it something else?

here's the code:
Sub Worksheet_Change(ByVal Target As Range)
If Target.Column <> 8 Then Exit Sub 'Column 8 is column H (Status)
If Target.Row < 13 Then Exit Sub 'Row 13 is the first row of data
Application.EnableEvents = False
Select Case LCase(Target.Value) 'I dont know what case user will input data in
Case "maps issued"
Target.EntireRow.Interior.ColorIndex = 35
Case "complete"
Target.EntireRow.Interior.ColorIndex = 35
Case "confirmed"
Target.EntireRow.Interior.ColorIndex = 36
Case "waiting on team"
Target.EntireRow.Interior.ColorIndex = 40
Case "no show"
Target.EntireRow.Interior.ColorIndex = 22
Case "team cancelled"
Target.EntireRow.Interior.ColorIndex = 22
Case "sent up"
Target.EntireRow.Interior.ColorIndex = 36
Case Else
Target.EntireRow.Interior.ColorIndex = xlColorIndexAutomatic
End Select
Application.EnableEvents = True 'should be part of Change macro
End Sub

--Thanks

Configuration: Windows XP, Excel 2003

Best answers for « Excel conditional formatting row color » in :
Avoid duplicates in Excel ShowAvoid duplicates in Excel In order to avoid duplication when encoding in a column from an excel sheet: take the conditional format on the first cell under the headings (eg A2) choose the following formula:...
Unlimited Conditional Formatting ShowUnlimited Conditional Formatting Introduction Principle Code Introduction The limitation of MFC (Conditional Formatting) to Excel version 2007 is less than 3. This is very short. Having seen many applications to push the limit, I am...
Colouring cells on conditions ShowColouring cells on conditions There are many pratical functions under Excel which is not commonly used. Example: If you wish a cell automatically turns red (or other formatting border, frame etc) under one condition: a result, a...
Spreadsheets - Conditional expressions ShowWhat is a Conditional Structure? Conditional structures are instructions that allow to test if a condition is true or not. Conditional structures may be associated together. To successfully execute these tests using logical functions, spreadsheets...

1

Excelguru, on May 14, 2009 7:41:56 am BST
  • +3

Remove the line
Application.EnableEvents =false

Add the following code and run once
Sub changeApplicationEnableEvents2truee()
Application.EnableEvents = True
End Sub Winners are losers who got up and gave it one more try. -Den­nis DeYoung

Reply to Excelguru

6

JC, on Aug 21, 2009 4:42:49 pm BST

I deleted the line "Application.EnableEvents=False" in the code of the Post/Question, but when you say " Add The following code....." did you want this new code in a new sub or placed in the deleted code??

Reply to JC

7

Excelguru, on Aug 21, 2009 4:47:54 pm BST

In a new sub
Run only once This is to make the EnableEvents to true in the application(excel) A wise man once said, 'I complained that I had no shoes unti­l I met a man who had no feet.'
I am interested in financial Modelling and custom excel deve­lopment with excel macros.

Reply to Excelguru

8

JC, on Aug 21, 2009 6:40:33 pm BST

Thanks for the fast response. I added the sub and ran the macro, but nothing happened. In addition, when I ran the Worksheet_Change macro I got an error "argument not optional" I don't have any experience with macro's and very little with VB, but usually my logic comes through...not this time I guess. I have 8 columns of data starting in row 4 and in column 7 is a validation list with 4 options (status options) What I want to do is change the background color of each row (Starting with 4, but only through Column 1:8) to correspond to the option selected in the validation list. Example: When I select "Acquired" in the Column 7 drop down list, I want the cooresponding row (not entire row, just column 1 through 8) to turn the color I assign to "Acquire" (which is green) The code I used (which I pasted below) makes sence to me as a workable macro, but excel doesn't agree with me. I initiated the macro by opening VB, Adding a module, entering the code (as shown below) closing the VB window then running once....changeApplicationEnableEvents2truee in the appropriate excel workbook. When nothing happened I tried running once.....worksheet_change in the appropriate excel worksheet and I got the error message I mentioned above.

So I ask, where did I go wrong? and is there a solution or another avenue I can attemp like coditional formatting. I do have 4 colors which is no good for excel 2003, maybe there is a work around. I don't know conditional formating so if that is the way to go, what do I do...use "cell value is or formula is" and if cell value is text, how do I manage that and also include A4:H4 of the row. If I use a formula, what is it?

I know this is alot of information and questions, you don't have to respond if you don't want to, but It would be great if you did and I beileve it can't hurt to ask. Thanks Here is the code I mentioned:
____________________________________________________________________________
Sub Worksheet_Change(ByVal Target As Range)
If Target.Column <> 7 Then Exit Sub 'Column 7 is column G (Status)
If Target.Row < 4 Then Exit Sub 'Row 4 is the first row of data
Select Case LCase(Target.Value) 'I dont know what case user will input data in
Case "maps issued"
Target.EntireRow.Interior.ColorIndex = 3
Case "Declined"
Target.EntireRow.Interior.ColorIndex = 4
Case "Acquired"
Target.EntireRow.Interior.ColorIndex = 5
Case "Not Acquired"
Target.EntireRow.Interior.ColorIndex = 6
Case "Pending"
Target.EntireRow.Interior.ColorIndex = xlColorIndexAutomatic
End Select
Application.EnableEvents = True 'should be part of Change macro
End Sub
__________________________________________________________________________
Sub changeApplicationEnableEvents2truee()
Application.EnableEvents = True
End Sub

Reply to JC

9

Excelguru, on Aug 22, 2009 3:13:26 pm BST
  • +1

You are using Lcase and then you are using "A"cquired, "R"ejected etc A wise man once said, 'I complained that I had no shoes until I met a man who had no feet.'
I am interested in financial Modelling and custom excel development with excel macros.

Reply to Excelguru

2

Bohemian, on Jun 12, 2009 5:53:38 pm BST
  • +15

Can this be done using Conditional Formatting?
(Chaging the color of A1:H1 based on value or text in H1)

Reply to Bohemian

3

Excelguru, on Jun 14, 2009 1:40:22 pm BST
  • +7

Yes
when you do conditonal formatting, in the condition, lock the cell address as in $A1 Winners are losers who got up and gave it one more try. -Den­nis DeYoung
My Interests are financial Modelling and custom excel develo­pment.

Reply to Excelguru

4

grumpie, on Jun 18, 2009 4:32:19 pm BST

Excelguru,

I was wondering how to lock the cell address with conditionalformatting?

Reply to grumpie

5

Excelguru, on Jun 27, 2009 1:13:57 pm BST
  • +4

I mean the use of $ to lock the cell reference (Just read it twice: lock the cell address as in $A1 ) Winners are losers who got up and gave it one more try. -Den­nis DeYoung
My Interests are financial Modelling and custom excel develo­pment.

Reply to Excelguru

10

taz, on Oct 23, 2009 9:02:25 am BST

I am trying to use the condtional formula to hightlight the row if say H cell contains a value greater than 12.
but i cant getit going because the H cell has formula referring to the other sheet. please advice

Reply to taz

11

 Excelguru, on Oct 28, 2009 9:30:24 am GMT

Conditional formatting checks only the value in a cell and NOT the formula in the cell

Do use of $ to lock the cell reference (column ID only as in $A1 ) to work for a row based on a cell value A wise man once said, 'I complained that I had no shoes unti­l I met a man who had no feet.'
I am interested in financial Modelling and custom excel deve­lopment with excel macros.

Reply to Excelguru