简体   繁体   中英

VBA Excel conditional formatting IF - THEN date

I want to do conditionnal formating with the following rules:

If a cell of my colum B is purple then apply the following rules on my column A that contains dates:

=TODAY()-A1>1<31 - color Pink =TODAY()-A1>30<61 - color Green

you get the point

However, if the content of my cell in the column B is blue, then I want my cell in the column A to be blue as well. I'm at the point that I dont even know if my formula is right. Thnks

You can use a UDF in a conditional formatting rule:

Function IsYellow(c) As Boolean
    IsYellow = (c.Interior.Color = vbYellow)
End Function

Updates will only get triggered when the sheet recalculates though.

An option for this is to go the VBA route, which would apply "conditional formatting" to cells as you go. For example:

For A_row = 1 To 100
  If Range(A_row, "B").Interior.ColorIndex = my_color_index Then
    Range(A_row, "A").NumberFormat = my_custom_format
    'add desired custom number formats here
  End If
Next

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM