VBA to condition format value base on font color in another sheet.

hajiali

Well-known Member
Joined
Sep 8, 2018
Messages
624
Office Version
  1. 2016
Platform
  1. Windows
Cell U5 using the following code to pull all agents if dates in range 'EMPLOYEE LIST'!$V$2:$BG$1000 is = to DATE($J$1,$G$1,$H$1 and dragged down to Cell U26

VBA Code:
=IFERROR(INDEX('EMPLOYEE LIST'!$G$2:$G$1000,AGGREGATE(15,6,(ROW('EMPLOYEE LIST'!$G$2:$G$1000)-ROW('EMPLOYEE LIST'!G$2)+1)/(('EMPLOYEE LIST'!$V$2:$BG$1000=DATE($J$1,$G$1,$H$1))),ROWS($U$5:U5))),"")

'EMPLOYEE LIST'!$V$2:$BG$1000 will be manually format date to be "RED" when it is a PM Hours.
'EMPLOYEE LIST'!$G$2:$G$1000 = Names of employee

What im need the VBA to do is conditional format employee name U5:U26 to be "RED" based on if the date corresponding to the Name is RED.

ex.
sheet Employee List
JOHN1/181/19
MIKE1/19
KIM1/19
JENN1/191/20
JAMES1/11/151/19

in BASE SHEET if DATE($J$1,$G$1,$H$1)=
J1= 2020 (year)
G1= 1 (month)
H1= 19 (Day)

U5:U26 results should be
JOHN
MIKE
KIM
JENN
JAMES

any help is greatly appreciated. let me know if you have any question.

Thanks
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
See if this code helps :)

Create module and place this code there.

VBA Code:
Public Function fFindColor(Target As Range, Color As Long) As Boolean
  Dim sCell As Range, ff As Boolean
  fFindColor = False
  For Each sCell In Target
    Debug.Print sCell.Address & " | " & sCell.Font.Color
    If sCell.Font.Color = Color Then
      fFindColor = True
      Exit For
    End If
  Next
End Function

Book1
AB
1Red in B1:B5Black
2FalseBlack
3Black
4Black
5Black
6Red in B7:B9
7TrueRed
8Red
9Red
10Red
11Red
MrExcel Help
Cell Formulas
RangeFormula
A2A2=fFindColor(B1:B6, 255 )
A7A7=fFindColor(B7:B9, 255)
 
Upvote 0
See if this code helps :)

Create module and place this code there.

VBA Code:
Public Function fFindColor(Target As Range, Color As Long) As Boolean
  Dim sCell As Range, ff As Boolean
  fFindColor = False
  For Each sCell In Target
    Debug.Print sCell.Address & " | " & sCell.Font.Color
    If sCell.Font.Color = Color Then
      fFindColor = True
      Exit For
    End If
  Next
End Function

Book1
AB
1Red in B1:B5Black
2FalseBlack
3Black
4Black
5Black
6Red in B7:B9
7TrueRed
8Red
9Red
10Red
11Red
MrExcel Help
Cell Formulas
RangeFormula
A2A2=fFindColor(B1:B6, 255 )
A7A7=fFindColor(B7:B9, 255)

this could help however I will need to figure out the cell that has the date in red corresponding to the name. instead of range in =fFindColor(B1:B6, 255 ) I will need it to be the specific cell. I would think just do not know how to go about it.
 
Upvote 0
huh?

All you need to do is use the tool available 'Conditional Formatting'

Book1
UVWX
5JOHN1/18/20201/19/2020
6MIKE1/19/2020
7KIM1/19/2020
8JENN1/19/20201/20/2020
9JAMES1/1/20201/15/20201/19/2020
MrExcel Help
Cells with Conditional Formatting
CellConditionCell FormatStop If True
U5:U9Expression=fFindColor(V5:W5,255)textNO
 
Last edited:
Upvote 0
This code is required in a module or imported from text file with .bas extension is required for the above conditional formatting to work.

VBA Code:
Attribute VB_Name = "modFindColor"
Public Function fFindColor(Target As Range, Color As Long) As Boolean
  Dim sCell As Range, ff As Boolean
  fFindColor = False
  For Each sCell In Target
    If sCell.Font.Color = Color Then
      fFindColor = True
      Exit For
    End If
  Next
End Function
 
Upvote 0
huh?

All you need to do is use the tool available 'Conditional Formatting'
the values change as the date in Base Sheet changes. I would like the outcome to auto Conditional Format based on the conditional formatting of the date in the other sheet. if you look at my example date 1/19 are in red for John and Kim so when i Change the date(2020,1,19) in sheet base sheet when it pulls the name John and Kim for the 19 it auto conditional formats those 2 in red.

another ex. in sheet Employee List
G.........VWX.......
JOHN1/201/19
MIKE1/20
KIM1/20
JENN1/191/20
JAMES1/11/201/19

in BASE SHEET if i change the DATE($J$1,$G$1,$H$1)=1/20/2020
J1= 2020 (year)
G1= 1 (month)
H1= 20 (Day)

U5:U26 results should be
JOHN
MIKE
KIM
JENN
JAMES

in this ex Mike, Jenn, and James should appear red BC the Date 1/20 in there rows are in red

hope this clarifies
 
Upvote 0
Ummm My example does EXACTLY THAT if you format those date colors RED, it will make the name RED

All you need to do is use the tool available 'Conditional Formatting'

Book1
UVWX
5JOHN1/18/20201/19/2020
6MIKE1/19/2020
7KIM1/19/2020
8JENN1/19/20201/20/2020
9JAMES1/1/20201/15/20201/19/2020
MrExcel Help
Cells with Conditional Formatting
CellConditionCell FormatStop If True
U5:U9Expression=fFindColor(V5:W5,255)textNO
 
Upvote 0
huh?

All you need to do is use the tool available 'Conditional Formatting'

Book1
UVWX
5JOHN1/18/20201/19/2020
6MIKE1/19/2020
7KIM1/19/2020
8JENN1/19/20201/20/2020
9JAMES1/1/20201/15/20201/19/2020
MrExcel Help
Cells with Conditional Formatting
CellConditionCell FormatStop If True
U5:U9Expression=fFindColor(V5:W5,255)textNO
Sorry misunderstood the the equation goes to conditioning formatting for those cells I will try that when I’m back on the computer.thanks
 
Upvote 0
Ummm My example does EXACTLY THAT if you format those date colors RED, it will make the name RED

So I tried your example on new sheet and it works. however, my Sheet Named "BASE SCH" cell U5 has the following formula
VBA Code:
=IFERROR(INDEX('EMPLOYEE LIST'!$G$2:$G$1000,AGGREGATE(15,6,(ROW('EMPLOYEE LIST'!$G$2:$G$1000)-ROW('EMPLOYEE LIST'!G$2)+1)/(('EMPLOYEE LIST'!$V$2:$BG$1000=DATE($J$1,$G$1,$H$1))),ROWS($U$5:U5))),"")

and Dragged down to U26. This generates/pull all employees in Sheet "Employee List" if dates in range $V$2:$BG$1000= DATE($J$1,$G$1,$H$1) in sheet "BASE SCH" the names that need to condition formatting and dates are in different sheet.

and if im correct your example does it only if there on the same sheet?
 
Upvote 0
No, you are incorrect that formula goes into the conditional formatting not the cell contents. It will use the cell value of whatever RANGE you put into the function. Another page wont matter and it could even be a named range.

So I tried your example on new sheet and it works. however, my Sheet Named "BASE SCH" cell U5 has the following formula
VBA Code:
=IFERROR(INDEX('EMPLOYEE LIST'!$G$2:$G$1000,AGGREGATE(15,6,(ROW('EMPLOYEE LIST'!$G$2:$G$1000)-ROW('EMPLOYEE LIST'!G$2)+1)/(('EMPLOYEE LIST'!$V$2:$BG$1000=DATE($J$1,$G$1,$H$1))),ROWS($U$5:U5))),"")

and Dragged down to U26. This generates/pull all employees in Sheet "Employee List" if dates in range $V$2:$BG$1000= DATE($J$1,$G$1,$H$1) in sheet "BASE SCH" the names that need to condition formatting and dates are in different sheet.

and if im correct your example does it only if there on the same sheet?
 
Upvote 0

Forum statistics

Threads
1,215,036
Messages
6,122,796
Members
449,095
Latest member
m_smith_solihull

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