+ Reply to Thread
Results 1 to 6 of 6

Conditional formatting - more than 3 conditions - result based on another cell

  1. #1
    Registered User
    Join Date
    08-03-2009
    Location
    London, UK
    MS-Off Ver
    Excel Mac 2008 & Excel 2003
    Posts
    7

    Lightbulb Conditional formatting - more than 3 conditions - result based on another cell

    I have established that to have more than 3 conditions in my version of Excel (2003) i have to use VBA. Unfortunately I have very little knowledge of this process.

    I have attached an example of the worksheet I am working on

    The worksheet in question totals hours worked for payroll.

    Problem:

    Required result: Cell to change to 1 of 8 background colours in response to selection of 1 of 8 options in drop down list in the cell directly next it.

    i.e. (in reference to attachment - sheet DATA)
    IF E6 = Holiday, then D6 = Red
    IF E6 = Half Day Holiday, then D6 = Red
    IF E6 = Sick, then D6 = Blue
    IF E6 = Sick Half Day, then D6 = Blue
    IF E6 = Bank Holiday, then D6 = Green
    IF E6 = Compassionate Leave, then D6 = Pink
    IF E6 = Unpaid Leave then, D6 = Yellow
    IF E6 = Unpaid Leave Half Day then, D6 = Yellow

    However, the same basic table as shown in sheet DATA appears several times on the worksheet. And in each instance the conditional formatting is the same (in reference to the relative cells).

    Does this make sense? This is my first post after several hours of research on the subject. Please advise if post is in wrong place/clarification is necessary etc. I have done my best to adhere to the forum rules.

    Many, many thanks.

    DAN COOPER
    Attached Files Attached Files
    Last edited by Mostlygood; 08-03-2009 at 10:49 AM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Conditional formatting - more than 3 conditions - result based on another cell

    Right-click on the sheet where you want this to occur and select VIEW CODE.

    Paste in this sheet event macro:
    Please Login or Register  to view this content.
    Press Alt-Q to close the VBEditor.
    Save your sheet.

    Give it a try. I've highlighted the part of the code where you indicate what range of cells to watch, so adjust that if you change the layout of your sheet.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    08-03-2009
    Location
    London, UK
    MS-Off Ver
    Excel Mac 2008 & Excel 2003
    Posts
    7

    Re: Conditional formatting - more than 3 conditions - result based on another cell

    Thank you very much for your swift reply. I will try straight away.

    I have just updated the post to reflect some changes. And was hoping it would be up before anyone answered. My mistake. I will try adding the new conditions to the VBA code myself and if I get stuck get back to you, if you don't mind.

    Once again, thanks

    D

  4. #4
    Registered User
    Join Date
    08-03-2009
    Location
    London, UK
    MS-Off Ver
    Excel Mac 2008 & Excel 2003
    Posts
    7

    Re: Conditional formatting - more than 3 conditions - result based on another cell

    SOLVED IT!

    Thanks so much, added the additional lines of VBA code and works like a treat.
    THANK

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Conditional formatting - more than 3 conditions - result based on another cell

    Like so:
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    04-16-2013
    Location
    lincoln
    MS-Off Ver
    Excel 2003
    Posts
    1

    Re: Conditional formatting - more than 3 conditions - result based on another cell

    i have changed the above code to suit my needs but it will not allow me to add columns AM,AN to the range as soon as i do it comes up with an error code can you help?


    Option Explicit

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim cell As Range
    For Each cell In Target
    If Not Intersect(cell, Range("J5:J129,K5:K129,L5:l129,M5:M129,N5:N129,O5:O129,P5:P129,Q5:Q129,R5:R129,S5:S129,T5:T129,U5:U129,V5:V129,W5:W129,X5:X129,Y5:Y129,Z5:Z129,AA5:AA129,AB5:AB129,AC5:AC129,AD5:AD129,AE5:AE129,AF5:AF129,AG5:AG129,AH5:AH129,AI5:AI129,AJ5:AJ129,AK5:AK129,AL1:AL129")) Is Nothing Then
    Select Case cell.Value
    Case "L", "ML", "RS"
    cell.Interior.ColorIndex = 10
    Case "S", "O", "OR"
    cell.Interior.ColorIndex = 7
    Case "SP"
    cell.Interior.ColorIndex = 6
    Case "C"
    cell.Interior.ColorIndex = 4
    Case "T", "DC"
    cell.Interior.ColorIndex = 8
    Case "B"
    cell.Interior.ColorIndex = 41
    Case "G", "GT", "IP"
    cell.Interior.ColorIndex = 3
    Case "CC"
    cell.Interior.ColorIndex = 44
    Case "N"
    cell.Interior.ColorIndex = 45
    Case Else
    cell.Interior.ColorIndex = xlNone
    End Select
    End If
    Next cell
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1