+ Reply to Thread
Results 1 to 3 of 3

Alert by cell color change

Hybrid View

  1. #1
    Registered User
    Join Date
    12-22-2011
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2007
    Posts
    26

    Alert by cell color change

    Hi everyone,

    I am looking for a macro that when the below conditions are true, then color the cell in column I light green (Standard colors).


    1. If a cell in column U has a date that is older than seven days. (Ignore blank cells)
    2. And if there is not a number/text in column M (Ignore when cells have a number/text)
    Then color the cell in column I light green (Standard colors).

    This can be either, a stand alone macro or I can add it to an existing macro.

    I would rather not use conditional formatting as there are already several on the tab. Since rows are deleted and added regularly, I find it necessary to update the formulas often when using conditional formatting.

    Thank you in advance.

    Alvin

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Alert by cell color change

    Hi Alvin,

    Try the following Macro. I also included a Macro to get the color of the Active cell so you can change the color if you don't like my green.

    Option Explicit
    
    Sub ColorMeLightGreen()
    
      Const sColumnRANGE = "U:U"
      Const nLightGreenColorINDEX = 35
    
      Dim myRange As Range
      Dim myRangeConstants As Range
      Dim myRangeFormulas As Range
      Dim r As Range
      
      Dim myDate As Date
      Dim myTargetDate As Date
      
      Dim iRow As Long
      
      Dim sValueinColumnM As String
      Dim sValueinColumnU As String
      
      Set myRangeConstants = ActiveSheet.Range(sColumnRANGE).SpecialCells(xlCellTypeConstants)
      Set myRangeFormulas = ActiveSheet.Range(sColumnRANGE).SpecialCells(xlCellTypeFormulas)
      Set myRange = Union(myRangeConstants, myRangeFormulas)
      
      'Get the Target Date (7 days ago)
      myTargetDate = Date - 7#
      
      For Each r In myRange
        Debug.Print r.Address(False, False)
        
        'Get the value from Column U
        sValueinColumnU = r.Value
        
        'Get the row number
        'Get the value in Column M (without leading and trailing spaces)
        iRow = r.Row
        sValueinColumnM = Trim(ActiveSheet.Cells(iRow, "M").Value)
        
        'Continue only if the Value in Column 'U' is a DATE and
        'Column 'M' is BLANK
        If IsDate(sValueinColumnU) And Len(sValueinColumnM) = 0 Then
          myDate = CDate(sValueinColumnU)
          
          If myDate < myTargetDate Then
            ActiveSheet.Cells(iRow, "M").Interior.ColorIndex = nLightGreenColorINDEX
          End If
          
        End If
      Next r
    
    
    End Sub
    
    Sub GetColorOfActiveCell()
      'This will give you the 'RGB Color' and the 'ColorIndex' of the Active Cell
      
      Dim myRGB_Color As Long
      myRGB_Color = ActiveCell.Interior.Color
      MsgBox ActiveCell.Address(False, False) & " = " & LjmConvertLongToRGB(myRGB_Color) & vbCrLf & _
             "ColorIndex is " & ActiveCell.Interior.ColorIndex
      
      
    End Sub
    
    Private Function LjmConvertLongToRGB(Color As Long) As String
      'This converts an RGB long into an RGB string.
      'Note use the build in VBA function RGB(Red, Green, Blue) for the inverse
      
      Dim iBlue As Integer
      Dim iGreen As Integer
      Dim iRed As Integer
      
      iRed = Color Mod 256
      iGreen = (Color \ 256) Mod 256
      iBlue = (Color \ 256 \ 256) Mod 256
      
      LjmConvertLongToRGB = "RGB( " & Format(iRed, "@@@") & ", " & Format(iGreen, "@@@") & ", " & Format(iBlue, "@@@") & ")"
    End Function
    Lewis

  3. #3
    Registered User
    Join Date
    08-27-2013
    Location
    Texas
    MS-Off Ver
    Excel 2010
    Posts
    30

    Re: Alert by cell color change

    I'm assuming you can change the spreadsheet however you want.
    I'd add a column beside U... In Column V make it a small width column. This way the color change will be a small box, highlighting the key items.
    Then add and equation

    If(AND(U1>=Now-7,M1=""),1,0)

    Then run some code the moves down Column V searching for 1's and change the color

    psuedo code:
    Set ws = Sheets("WhateverYourSheetIsCalled")
    ws.range("V1:V" & bottomrow) = "=If(AND(U1>=Now-7),M1=""),1,0)"
    BottomRow = SomeNumber
    nLightGreenColorINDEX = 35
    
    For each CL in ws.Range("V1:V" & bottomrow)
         If CL = 1 then 
             .Interior.ColorIndex = nLightGreenColorINDEX
         End if
    Next CL
    Last edited by briguin; 02-09-2015 at 11:18 PM.

+ 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. Pop up to alert for a certain change in value in a cell
    By sbab in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-02-2013, 05:47 AM
  2. Cell Value Change Alert
    By devesh05 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-12-2010, 08:59 AM
  3. Cell Color Alert by Date
    By MattVarnell in forum Excel General
    Replies: 3
    Last Post: 12-13-2009, 04:33 AM
  4. Alert me if cell is not in list when user clicks to change it
    By JK1234 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-20-2009, 11:50 AM
  5. Sound+color alert if cell changed in another worksheet
    By florinel in forum Excel General
    Replies: 0
    Last Post: 05-25-2006, 11:52 AM

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