Conditional formatting entire row based on values in four cells

chriswalker32

New Member
Joined
Mar 23, 2011
Messages
9
Hi all - newbie here (having used the forum numerous time before for advice)

I would really apprecaite it if someone could assist me with the following query regarding conditional formatting in Excel.

I am currently working on a timetable within Excel which requires row colour to be changed to reflect four different authorisation points i.e.

If Person 1 authorises a document by entering a date in cell K2, row 2 changes to yellow;
If Person 2 authorises a document by entering a date in cell L2, row 2 changes to orange;
If Person 3 authorises a document by entering a date in cell M2, row 2 changes to blue; and
If Person 4 authorises a document by entering a date in cell N2, row 2 changes to green.

All rows need to be white by default until any level of authorisation occurs.

At present, I am able to cater for three conditions using conditional formatting however it would be really useful to cater for all four conditions using VBA code. I have little experience in code writing and would really appreciate some information on how to use VBA to allow for these four conditions.

Happy to send over the excel spreadsheet in question if I have not been clear!
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Hi. Try this: right click the sheet tab, select View Code and paste in

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If IsDate(Target.Value) Then
    Select Case Target.Column
        Case 11: Target.EntireRow.Interior.ColorIndex = 6
        Case 12: Target.EntireRow.Interior.ColorIndex = 44
        Case 13: Target.EntireRow.Interior.ColorIndex = 5
        Case 14: Target.EntireRow.Interior.ColorIndex = 4
    End Select
End If
End Sub
 
Upvote 0
Hi VoG,

Thank you - thats exactly what I was after!
Is there a way to ensure that the rows remain white if no authorisation has occured?

Thanks again!
 
Upvote 0
Maybe like this

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If IsDate(Target.Value) Then
    Select Case Target.Column
        Case 11: Target.EntireRow.Interior.ColorIndex = 6
        Case 12: Target.EntireRow.Interior.ColorIndex = 44
        Case 13: Target.EntireRow.Interior.ColorIndex = 5
        Case 14: Target.EntireRow.Interior.ColorIndex = 4
    End Select
Else
    If Target.Column >= 11 And Target.Column <= 14 Then Target.EntireRow.Interior.ColorIndex = xlNone
End If
End Sub
 
Upvote 0
Thanks!

one final thing - if , for example, AG is the last column in the table is there any way to ensure that only a2:ag2 is coloured?
 
Upvote 0
Try like this

Code:
Range("A" & Target.Row).Resize(, 33).Interior.ColorIndex = 6
 
Upvote 0
Why for some reason this code is not working on my sheet? I even open a new sheet and pasted this code, but still there is no event bieng triggered.....
 
Upvote 0
Why for some reason this code is not working on my sheet? I even open a new sheet and pasted this code, but still there is no event bieng triggered.....


Make sure that events are enabled. In the code window press ALT + G then in the Immediate Window type

Application.EnableEvents=True

and press Enter.
 
Upvote 0
Hi Vog,

This is how I put the enable event code
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If IsDate(Target.Value) Then
    Select Case Target.Column
        Case 17: Target.EntireRow.Interior.ColorIndex = 6
        Case 19: Target.EntireRow.Interior.ColorIndex = 44
        Case 31: Target.EntireRow.Interior.ColorIndex = 4
        'Case 14: Target.EntireRow.Interior.ColorIndex = 4
    End Select
Else
    If Target.Column >= 17 And Target.Column <= 31 Then Target.EntireRow.Interior.ColorIndex = xlNone
End If
Application.EnableEvents = True
End Sub
However the ALT+G thing I don't know how..
 
Upvote 0

Forum statistics

Threads
1,224,534
Messages
6,179,390
Members
452,909
Latest member
VickiS

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top