+ Reply to Thread
Results 1 to 4 of 4

changing cell colour based on other and multiple cell values

Hybrid View

  1. #1
    Registered User
    Join Date
    02-25-2019
    Location
    Newcastle
    MS-Off Ver
    2013
    Posts
    9

    changing cell colour based on other and multiple cell values

    Hi There,

    I am trying to right some vba code that changes the colour of a cell depending on which cell has values filled.

    Ie

    If cell A2 has a value then cell A1 is red

    If cell A2 and A3 has a value then A1 is orange

    If Cell A2, A3, A4 has a value then A1 is yellow

    If cell A2, A3, A4 and A5 has a value then A1 is Green


    The idea above is an example and the cell refs will be different but just an idea of the aim.

    I would also have multiple work sheets and want it to run thru each work sheet

    Below is some code I started to write but it only makes the a1 cells red and doesn’t then change to orange or yellow when the other cells have the “Y” value

    Any help would be greatly appreciated




    Private Sub Worksheet_Change(ByVal Target As Range)
       
       
       
       Dim I As Long
       Dim r1 As Range, r2 As Range, r3 As Range, r4 As Range, r5 As Range
       
       For I = 1 To 11
          
       Set r1 = Range("A" & I)
       Set r2 = Range("B" & I)
       Set r3 = Range("C" & I)
       Set r4 = Range("D" & I)
       Set r5 = Range("E" & I)
       
       If r2.Value = "Y" Then r1.Interior.Color = vbRed
       If r2.Value = "Y" & r3.Value = "Y" Then r1.Interior.Color = RGB(255, 192, 0)
       If r2.Value = "Y" & r3.Value = "Y" & r4.Value = "Y" Then r1.Interior.Color = vbYellow
       If r2.Value = "Y" & r3.Value = "Y" & r4.Value = "Y" & r5.Value = "Y" Then r1.Interior.Color = vbGreen
       
       Next I
    
    End Sub

  2. #2
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,132

    Re: changing cell colour based on other and multiple cell values

    Replace the & with And

  3. #3
    Registered User
    Join Date
    02-25-2019
    Location
    Newcastle
    MS-Off Ver
    2013
    Posts
    9

    Re: changing cell colour based on other and multiple cell values

    cheers that sorted it

  4. #4
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,132

    Re: changing cell colour based on other and multiple cell values

    You're welcome & thanks for the feedback

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Changing the colour of a cell based on PART of the text of the cell
    By Sanglorian in forum Word Programming / VBA / Macros
    Replies: 4
    Last Post: 11-11-2014, 12:48 AM
  2. [SOLVED] Changing the cell colour based on what is input in another cell.
    By MissMay in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 09-21-2013, 10:21 AM
  3. Changing the colour of a cell based on the colour of another cell
    By Pete2931 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-11-2012, 03:35 AM
  4. changing row colour depending on multiple cell values
    By Erikp in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-15-2011, 06:57 PM
  5. Changing cell fill colour based on date in cell - Multiple rows
    By ExcelNewb2010 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-26-2010, 07:30 AM
  6. Changing Cell Fill Colour based on another cell value
    By MoonWeazel in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-02-2008, 10:15 AM
  7. changing cell colour using based on cell value
    By baggy098 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-30-2006, 08:07 PM

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