index match extract cells with certain font color

hajiali

Well-known Member
Joined
Sep 8, 2018
Messages
624
Office Version
  1. 2016
Platform
  1. Windows
Hello all Im looking to see how I can extract cells with certain font ColorIndex.

I have the Following Macro

VBA Code:
Function GetFontColor(ByVal Target As Range) As Integer
    GetFontColor = Target.Font.ColorIndex
End Function

The formula i have tried did not work. in my example I'm trying to get all Names if the font color EList[[F1]:[F10] appears the 41 color index

Excel Formula:
=INDEX(EList[LAST, FIRST],AGGREGATE(15,6,(ROW(EList[LAST, FIRST])-ROW(F2)+1)/(GetFontColor(EList[[F1]:[F10]])=41),ROWS(X15:X15)))

any help is greatly appreciated.

Thanks,
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Hello all Im looking to see how I can extract cells with certain font ColorIndex.

I have the Following Macro

VBA Code:
Function GetFontColor(ByVal Target As Range) As Integer
    GetFontColor = Target.Font.ColorIndex
End Function

The formula i have tried did not work. in my example I'm trying to get all Names if the font color EList[[F1]:[F10] appears the 41 color index

Excel Formula:
=INDEX(EList[LAST, FIRST],AGGREGATE(15,6,(ROW(EList[LAST, FIRST])-ROW(F2)+1)/(GetFontColor(EList[[F1]:[F10]])=41),ROWS(X15:X15)))

any help is greatly appreciated.

Thanks,
Hard to help without a dataset to test it on, but which part of the formula isn't working? Have you broken it down to its constituent parts and tested each part first?
 
Upvote 0
Im certain its

Excel Formula:
(GetFontColor(EList[[F1]:[F10]])=41)

when Change that to

Excel Formula:
(EList[[F1]:[F10]]=W15)

where W15 is a date
EList[[F1]:[F10]] range are also dates. However I have designated dates with AM shift with ColorIndex = 41 and PM with colorIndex=9

using the following worksheet_change code in the sheet where EList[[F1]:[F10]]

VBA Code:
If Not FHLCells Is Nothing And Cells(FHLCells.Row, DECLD.Column) = "FHL" And FHLCells.Value2 <> "" Then
         With UserForm4
            .Tag = "AM"
            .Repaint
            .StartUpPosition = 0
            .Left = Application.Left + (0.5 * Application.Width) - (0.5 * .Width)
            .Top = Application.Top + (0.5 * Application.Height) - (0.5 * .Height)
            .Show
             If .Tag = "AM" Then
                Target.Font.ColorIndex = 41
                MsgBox "AM SHIFT WAS ADDED", vbOKOnly, "AM SHIFT"
             End If
             If .Tag = "PM" Then
                Target.Font.ColorIndex = 9
                 MsgBox "PM SHIFT WAS ADDED", vbOKOnly, "PM SHIFT"
             End If
         End With
    End If
 
Upvote 0
You don't need to be "certain" when you can test it and be "positive", but if you're using VBA, why not just use VBA to get the results?

But in any event - I tried your function and it works provided that the cells are all the same font color. If they're not, it returns an error.
 
Upvote 0
You don't need to be "certain" when you can test it and be "positive", but if you're using VBA, why not just use VBA to get the results?

But in any event - I tried your function and it works provided that the cells are all the same font color. If they're not, it returns an error.
glad you mentioned that with same font color. you are right it does work l tried that. So the point was to Distinguish between "AM" and "PM" the range will have different colors. is there any way beside VBA. the reason I wanted a formula instead of VBA is the sheet with this formula can be changed to different months and its for display/print purpose only
 
Upvote 0
glad you mentioned that with same font color. you are right it does work l tried that. So the point was to Distinguish between "AM" and "PM" the range will have different colors. is there any way beside VBA. the reason I wanted a formula instead of VBA is the sheet with this formula can be changed to different months and its for display/print purpose only
Conditional formatting?
 
Upvote 0
Book1
BHBIBJBKBLBMBNBOBPBQ
1F1F2F3F4F5F6F7F8F9F10
201/2803/0105/0605/0705/1005/1105/1205/1305/1412/12
301/3104/0205/3006/0706/0806/0908/1309/2109/2209/24
403/0903/1003/1103/1203/0404/0104/0204/1604/0905/02
501/1801/0210/0110/15
6
EMPLOYEE LIST
Cells with Conditional Formatting
CellConditionCell FormatStop If True
BQ2:BQ73Expression=BF2>=10textNO
BP2:BP73Expression=BF2>=9textNO
BO2:BO73Expression=BF2>=8textNO
BN2:BN73Expression=BF2>=7textNO
BM2:BM73Expression=BF2>=6textNO
BL2:BL73Expression=BF2>=5textNO
BK2:BK73Expression=BF2>=4textNO
BJ2:BJ73Expression=BF2>=3textNO
BI2:BI73Expression=BF2>=2textNO
BH2:BH73Expression=BF2>=1textNO



as shown above in cell BJ5 = 10/1/2022 in colorindex=41 for "AM" shift. and to the right is 10/15/22 in ColorIndex=9 for PM and we will have Black and Red fonts which needs to be ignored.
 
Upvote 0
Book1
WXYZAAABAC
14DAYFHL AMFHL AMFHL AMFHL PMFHL PMFHL PM
1510/1#NUM!
1610/2
1710/3
1810/4
1910/5
2010/6
2110/7
2210/8
2310/9
2410/10
2510/11
2610/12
2710/13
2810/14
2910/15
FHL
Cell Formulas
RangeFormula
X15X15=INDEX(EList[LAST, FIRST],AGGREGATE(15,6,(ROW(EList[LAST, FIRST])-ROW(F2)+1)/(GetFontColor(EList[[F1]:[F10]])=41),ROWS(X15:X15)))
W15W15=DATE(F2,BF4,1)
W16:W29W16=W15+1


in my other sheet Im needing to Pull all agents on AM on the AM section and All PM agents on PM section . ex. Agent in Column 5 should appear on AM for 10/1 but PM for 10/15
 
Upvote 0
Ahh I see. No conditional formatting won't help here. Personally, I would use VBA but someone might have a formula based solution. I'm racing out the door, but will check back in when get home later tonight in case no one has been able to help
 
Upvote 0
How about
VBA Code:
Function GetFontColor(ByVal Rng As Range) As Variant
    Dim i As Long, j As Long
    Dim Ary As Variant
    
    ReDim Ary(1 To Rng.Rows.Count, 1 To Rng.Columns.Count)
    For i = 1 To UBound(Ary)
      For j = 1 To UBound(Ary, 2)
         Ary(i, j) = Rng(i, j).Font.ColorIndex
      Next j
   Next i
   GetFontColor = Ary
End Function
 
Upvote 0
Solution

Forum statistics

Threads
1,215,398
Messages
6,124,699
Members
449,180
Latest member
craigus51286

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