Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
KD KD is offline
external usenet poster
 
Posts: 41
Default Filter by Colour - conditional formating

Hi,

I have created a condition in conditional formatting highlighting a specific
color. How can I filter by that colour (Red in this case).

Any help will be greatly appreciated.

Regards,
KD
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Filter by Colour - conditional formating

You can try out the below solution which uses a helper column and a UDF .

From workbook launch VBE using Alt+F11. From menu Insert a Module and paste
the below function.Close and get back to workbook and try the below formula.

In the helper column use the below formula and copy down as required. Cell
E1 is the first cell in the column which is conditional formatted...

=IF(getcfcolorindex(E1)=3,"Filter by red","")

Function GetCFColorIndex(C As Range) As Variant
Dim intCount As Integer, FC As FormatCondition, blnMatch As Boolean
If C.Count < 1 Then Exit Function
For intCount = 1 To C.FormatConditions.Count
'Loop through each Contidional Formatting
Set FC = C.FormatConditions(intCount)
Application.Volatile
If FC.Type = 1 Then
'Handle Type1-xlExpression (If 'Cell Value Is')
Select Case FC.Operator
Case xlBetween '1
If C.Value = GetCFV(FC.Formula1) And C.Value _
<= GetCFV(FC.Formula2) Then blnMatch = True: Exit For
Case xlNotBetween '2
If C.Value < GetCFV(FC.Formula1) Or C.Value _
GetCFV(FC.Formula2) Then blnMatch = True: Exit For

Case xlEqual '3
If C.Value = GetCFV(FC.Formula1) Then blnMatch = True: Exit For
Case xlNotEqual '4
If C.Value < GetCFV(FC.Formula1) Then blnMatch = True: Exit For
Case xlGreater '5
If C.Value GetCFV(FC.Formula1) Then blnMatch = True: Exit For
Case xlGreaterEqual '6
If C.Value = GetCFV(FC.Formula1) Then blnMatch = True: Exit For
Case xlLess '7
If C.Value < GetCFV(FC.Formula1) Then blnMatch = True: Exit For
Case xlLessEqual '8
If C.Value <= GetCFV(FC.Formula1) Then blnMatch = True: Exit For
End Select
Else
'Handle Type2-xlExternal (If 'Formula Is')
If Evaluate(Application.ConvertFormula( _
Application.ConvertFormula(FC.Formula1, xlA1, xlR1C1), _
xlR1C1, xlA1, , C)) Then blnMatch = True: Exit For
End If
Next

If blnMatch Then GetCFColorIndex = FC.Interior.ColorIndex
End Function
'-------------------------------------------------------------------------------
Function GetCFV(strData As Variant)
'Get text string or numeric from CF formula
If Not IsNumeric(strData) Then
GetCFV = Mid(strData, 3, Len(strData) - 3)
Else
GetCFV = CDbl(strData)
End If
End Function


If this post helps click Yes
---------------
Jacob Skaria


"kd" wrote:

Hi,

I have created a condition in conditional formatting highlighting a specific
color. How can I filter by that colour (Red in this case).

Any help will be greatly appreciated.

Regards,
KD

  #3   Report Post  
Posted to microsoft.public.excel.programming
KD KD is offline
external usenet poster
 
Posts: 41
Default Filter by Colour - conditional formating

Hi Jacob,

Thank you for the prompt reply.

The result is showing "Filter by red" against all the data, whereas the
condition is true in few cells only. Can you help?

Regards,
KD



"Jacob Skaria" wrote:

You can try out the below solution which uses a helper column and a UDF .

From workbook launch VBE using Alt+F11. From menu Insert a Module and paste
the below function.Close and get back to workbook and try the below formula.

In the helper column use the below formula and copy down as required. Cell
E1 is the first cell in the column which is conditional formatted...

=IF(getcfcolorindex(E1)=3,"Filter by red","")

Function GetCFColorIndex(C As Range) As Variant
Dim intCount As Integer, FC As FormatCondition, blnMatch As Boolean
If C.Count < 1 Then Exit Function
For intCount = 1 To C.FormatConditions.Count
'Loop through each Contidional Formatting
Set FC = C.FormatConditions(intCount)
Application.Volatile
If FC.Type = 1 Then
'Handle Type1-xlExpression (If 'Cell Value Is')
Select Case FC.Operator
Case xlBetween '1
If C.Value = GetCFV(FC.Formula1) And C.Value _
<= GetCFV(FC.Formula2) Then blnMatch = True: Exit For
Case xlNotBetween '2
If C.Value < GetCFV(FC.Formula1) Or C.Value _
GetCFV(FC.Formula2) Then blnMatch = True: Exit For

Case xlEqual '3
If C.Value = GetCFV(FC.Formula1) Then blnMatch = True: Exit For
Case xlNotEqual '4
If C.Value < GetCFV(FC.Formula1) Then blnMatch = True: Exit For
Case xlGreater '5
If C.Value GetCFV(FC.Formula1) Then blnMatch = True: Exit For
Case xlGreaterEqual '6
If C.Value = GetCFV(FC.Formula1) Then blnMatch = True: Exit For
Case xlLess '7
If C.Value < GetCFV(FC.Formula1) Then blnMatch = True: Exit For
Case xlLessEqual '8
If C.Value <= GetCFV(FC.Formula1) Then blnMatch = True: Exit For
End Select
Else
'Handle Type2-xlExternal (If 'Formula Is')
If Evaluate(Application.ConvertFormula( _
Application.ConvertFormula(FC.Formula1, xlA1, xlR1C1), _
xlR1C1, xlA1, , C)) Then blnMatch = True: Exit For
End If
Next

If blnMatch Then GetCFColorIndex = FC.Interior.ColorIndex
End Function
'-------------------------------------------------------------------------------
Function GetCFV(strData As Variant)
'Get text string or numeric from CF formula
If Not IsNumeric(strData) Then
GetCFV = Mid(strData, 3, Len(strData) - 3)
Else
GetCFV = CDbl(strData)
End If
End Function


If this post helps click Yes
---------------
Jacob Skaria


"kd" wrote:

Hi,

I have created a condition in conditional formatting highlighting a specific
color. How can I filter by that colour (Red in this case).

Any help will be greatly appreciated.

Regards,
KD

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Filter by Colour - conditional formating

Post your conditional formatting formula and the UDF formula which you tried
so as to recreate.

If this post helps click Yes
---------------
Jacob Skaria


"kd" wrote:

Hi Jacob,

Thank you for the prompt reply.

The result is showing "Filter by red" against all the data, whereas the
condition is true in few cells only. Can you help?

Regards,
KD



"Jacob Skaria" wrote:

You can try out the below solution which uses a helper column and a UDF .

From workbook launch VBE using Alt+F11. From menu Insert a Module and paste
the below function.Close and get back to workbook and try the below formula.

In the helper column use the below formula and copy down as required. Cell
E1 is the first cell in the column which is conditional formatted...

=IF(getcfcolorindex(E1)=3,"Filter by red","")

Function GetCFColorIndex(C As Range) As Variant
Dim intCount As Integer, FC As FormatCondition, blnMatch As Boolean
If C.Count < 1 Then Exit Function
For intCount = 1 To C.FormatConditions.Count
'Loop through each Contidional Formatting
Set FC = C.FormatConditions(intCount)
Application.Volatile
If FC.Type = 1 Then
'Handle Type1-xlExpression (If 'Cell Value Is')
Select Case FC.Operator
Case xlBetween '1
If C.Value = GetCFV(FC.Formula1) And C.Value _
<= GetCFV(FC.Formula2) Then blnMatch = True: Exit For
Case xlNotBetween '2
If C.Value < GetCFV(FC.Formula1) Or C.Value _
GetCFV(FC.Formula2) Then blnMatch = True: Exit For

Case xlEqual '3
If C.Value = GetCFV(FC.Formula1) Then blnMatch = True: Exit For
Case xlNotEqual '4
If C.Value < GetCFV(FC.Formula1) Then blnMatch = True: Exit For
Case xlGreater '5
If C.Value GetCFV(FC.Formula1) Then blnMatch = True: Exit For
Case xlGreaterEqual '6
If C.Value = GetCFV(FC.Formula1) Then blnMatch = True: Exit For
Case xlLess '7
If C.Value < GetCFV(FC.Formula1) Then blnMatch = True: Exit For
Case xlLessEqual '8
If C.Value <= GetCFV(FC.Formula1) Then blnMatch = True: Exit For
End Select
Else
'Handle Type2-xlExternal (If 'Formula Is')
If Evaluate(Application.ConvertFormula( _
Application.ConvertFormula(FC.Formula1, xlA1, xlR1C1), _
xlR1C1, xlA1, , C)) Then blnMatch = True: Exit For
End If
Next

If blnMatch Then GetCFColorIndex = FC.Interior.ColorIndex
End Function
'-------------------------------------------------------------------------------
Function GetCFV(strData As Variant)
'Get text string or numeric from CF formula
If Not IsNumeric(strData) Then
GetCFV = Mid(strData, 3, Len(strData) - 3)
Else
GetCFV = CDbl(strData)
End If
End Function


If this post helps click Yes
---------------
Jacob Skaria


"kd" wrote:

Hi,

I have created a condition in conditional formatting highlighting a specific
color. How can I filter by that colour (Red in this case).

Any help will be greatly appreciated.

Regards,
KD

  #5   Report Post  
Posted to microsoft.public.excel.programming
KD KD is offline
external usenet poster
 
Posts: 41
Default Filter by Colour - conditional formating

Conditional formatting applied in Cell M2.

That is if Cell Value is not equal to =B2 - Format--Patterns--Cell
Shading--Red color.

UDF in Column W: =IF(getcfcolorindex(M2)=3,"Filter by red","")

Regards,
KD

"Jacob Skaria" wrote:

Post your conditional formatting formula and the UDF formula which you tried
so as to recreate.

If this post helps click Yes
---------------
Jacob Skaria


"kd" wrote:

Hi Jacob,

Thank you for the prompt reply.

The result is showing "Filter by red" against all the data, whereas the
condition is true in few cells only. Can you help?

Regards,
KD



"Jacob Skaria" wrote:

You can try out the below solution which uses a helper column and a UDF .

From workbook launch VBE using Alt+F11. From menu Insert a Module and paste
the below function.Close and get back to workbook and try the below formula.

In the helper column use the below formula and copy down as required. Cell
E1 is the first cell in the column which is conditional formatted...

=IF(getcfcolorindex(E1)=3,"Filter by red","")

Function GetCFColorIndex(C As Range) As Variant
Dim intCount As Integer, FC As FormatCondition, blnMatch As Boolean
If C.Count < 1 Then Exit Function
For intCount = 1 To C.FormatConditions.Count
'Loop through each Contidional Formatting
Set FC = C.FormatConditions(intCount)
Application.Volatile
If FC.Type = 1 Then
'Handle Type1-xlExpression (If 'Cell Value Is')
Select Case FC.Operator
Case xlBetween '1
If C.Value = GetCFV(FC.Formula1) And C.Value _
<= GetCFV(FC.Formula2) Then blnMatch = True: Exit For
Case xlNotBetween '2
If C.Value < GetCFV(FC.Formula1) Or C.Value _
GetCFV(FC.Formula2) Then blnMatch = True: Exit For
Case xlEqual '3
If C.Value = GetCFV(FC.Formula1) Then blnMatch = True: Exit For
Case xlNotEqual '4
If C.Value < GetCFV(FC.Formula1) Then blnMatch = True: Exit For
Case xlGreater '5
If C.Value GetCFV(FC.Formula1) Then blnMatch = True: Exit For
Case xlGreaterEqual '6
If C.Value = GetCFV(FC.Formula1) Then blnMatch = True: Exit For
Case xlLess '7
If C.Value < GetCFV(FC.Formula1) Then blnMatch = True: Exit For
Case xlLessEqual '8
If C.Value <= GetCFV(FC.Formula1) Then blnMatch = True: Exit For
End Select
Else
'Handle Type2-xlExternal (If 'Formula Is')
If Evaluate(Application.ConvertFormula( _
Application.ConvertFormula(FC.Formula1, xlA1, xlR1C1), _
xlR1C1, xlA1, , C)) Then blnMatch = True: Exit For
End If
Next

If blnMatch Then GetCFColorIndex = FC.Interior.ColorIndex
End Function
'-------------------------------------------------------------------------------
Function GetCFV(strData As Variant)
'Get text string or numeric from CF formula
If Not IsNumeric(strData) Then
GetCFV = Mid(strData, 3, Len(strData) - 3)
Else
GetCFV = CDbl(strData)
End If
End Function


If this post helps click Yes
---------------
Jacob Skaria


"kd" wrote:

Hi,

I have created a condition in conditional formatting highlighting a specific
color. How can I filter by that colour (Red in this case).

Any help will be greatly appreciated.

Regards,
KD



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Filter by Colour - conditional formating

Try out the modified version..



Function GetCFColorIndex(c As Range) As Variant
Dim intCount As Integer, FC As FormatCondition, blnMatch As Boolean
If c.Count < 1 Then Exit Function
For intCount = 1 To c.FormatConditions.Count
'Loop through each Contidional Formatting
Set FC = c.FormatConditions(intCount)
Application.Volatile
If FC.Type = 1 Then
'Handle Type1-xlExpression (If 'Cell Value Is')
Select Case FC.Operator
Case xlBetween '1
If c.Value = GetCFV(FC.Formula1, c) And c.Value _
<= GetCFV(FC.Formula2, c) Then blnMatch = True: Exit For
Case xlNotBetween '2
If c.Value < GetCFV(FC.Formula1, c) Or c.Value _
GetCFV(FC.Formula2, c) Then blnMatch = True: Exit For

Case xlEqual '3
If c.Value = GetCFV(FC.Formula1, c) Then blnMatch = True: Exit For
Case xlNotEqual '4
If c.Value < GetCFV(FC.Formula1, c) Then blnMatch = True: Exit For
Case xlGreater '5
If c.Value GetCFV(FC.Formula1, c) Then blnMatch = True: Exit For
Case xlGreaterEqual '6
If c.Value = GetCFV(FC.Formula1, c) Then blnMatch = True: Exit For
Case xlLess '7
If c.Value < GetCFV(FC.Formula1, c) Then blnMatch = True: Exit For
Case xlLessEqual '8
If c.Value <= GetCFV(FC.Formula1, c) Then blnMatch = True: Exit For
End Select
Else
'Handle Type2-xlExternal (If 'Formula Is')
If Evaluate(Application.ConvertFormula( _
Application.ConvertFormula(FC.Formula1, xlA1, xlR1C1), _
xlR1C1, xlA1, , c)) Then blnMatch = True: Exit For
End If
Next

If blnMatch Then GetCFColorIndex = FC.Interior.ColorIndex
End Function
'-------------------------------------------------------------------------------
Function GetCFV(strData As Variant, c As Range)
'Get text string or numeric from CF formula
If IsNumeric(strData) Then
GetCFV = CDbl(strData)
ElseIf InStr(strData, Chr(34)) Then
GetCFV = Mid(strData, 3, Len(strData) - 3)
Else
GetCFV = Range(Mid(Application.ConvertFormula( _
Application.ConvertFormula(strData, xlA1, xlR1C1), _
xlR1C1, xlA1, , c), 2))
End If
End Function
'-------------------------------------------------------------------------------

If this post helps click Yes
---------------
Jacob Skaria


"kd" wrote:

Conditional formatting applied in Cell M2.

That is if Cell Value is not equal to =B2 - Format--Patterns--Cell
Shading--Red color.

UDF in Column W: =IF(getcfcolorindex(M2)=3,"Filter by red","")

Regards,
KD

"Jacob Skaria" wrote:

Post your conditional formatting formula and the UDF formula which you tried
so as to recreate.

If this post helps click Yes
---------------
Jacob Skaria


"kd" wrote:

Hi Jacob,

Thank you for the prompt reply.

The result is showing "Filter by red" against all the data, whereas the
condition is true in few cells only. Can you help?

Regards,
KD



"Jacob Skaria" wrote:

You can try out the below solution which uses a helper column and a UDF .

From workbook launch VBE using Alt+F11. From menu Insert a Module and paste
the below function.Close and get back to workbook and try the below formula.

In the helper column use the below formula and copy down as required. Cell
E1 is the first cell in the column which is conditional formatted...

=IF(getcfcolorindex(E1)=3,"Filter by red","")

Function GetCFColorIndex(C As Range) As Variant
Dim intCount As Integer, FC As FormatCondition, blnMatch As Boolean
If C.Count < 1 Then Exit Function
For intCount = 1 To C.FormatConditions.Count
'Loop through each Contidional Formatting
Set FC = C.FormatConditions(intCount)
Application.Volatile
If FC.Type = 1 Then
'Handle Type1-xlExpression (If 'Cell Value Is')
Select Case FC.Operator
Case xlBetween '1
If C.Value = GetCFV(FC.Formula1) And C.Value _
<= GetCFV(FC.Formula2) Then blnMatch = True: Exit For
Case xlNotBetween '2
If C.Value < GetCFV(FC.Formula1) Or C.Value _
GetCFV(FC.Formula2) Then blnMatch = True: Exit For
Case xlEqual '3
If C.Value = GetCFV(FC.Formula1) Then blnMatch = True: Exit For
Case xlNotEqual '4
If C.Value < GetCFV(FC.Formula1) Then blnMatch = True: Exit For
Case xlGreater '5
If C.Value GetCFV(FC.Formula1) Then blnMatch = True: Exit For
Case xlGreaterEqual '6
If C.Value = GetCFV(FC.Formula1) Then blnMatch = True: Exit For
Case xlLess '7
If C.Value < GetCFV(FC.Formula1) Then blnMatch = True: Exit For
Case xlLessEqual '8
If C.Value <= GetCFV(FC.Formula1) Then blnMatch = True: Exit For
End Select
Else
'Handle Type2-xlExternal (If 'Formula Is')
If Evaluate(Application.ConvertFormula( _
Application.ConvertFormula(FC.Formula1, xlA1, xlR1C1), _
xlR1C1, xlA1, , C)) Then blnMatch = True: Exit For
End If
Next

If blnMatch Then GetCFColorIndex = FC.Interior.ColorIndex
End Function
'-------------------------------------------------------------------------------
Function GetCFV(strData As Variant)
'Get text string or numeric from CF formula
If Not IsNumeric(strData) Then
GetCFV = Mid(strData, 3, Len(strData) - 3)
Else
GetCFV = CDbl(strData)
End If
End Function


If this post helps click Yes
---------------
Jacob Skaria


"kd" wrote:

Hi,

I have created a condition in conditional formatting highlighting a specific
color. How can I filter by that colour (Red in this case).

Any help will be greatly appreciated.

Regards,
KD

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 199
Default Filter by Colour - conditional formating

Put the same formula as used in conditional formatting in a helper
column. the value of the cells in a helper column in the same row with
colored cells will be true. then you could filter by that value, true.

Keiji

kd wrote:
Hi,

I have created a condition in conditional formatting highlighting a specific
color. How can I filter by that colour (Red in this case).

Any help will be greatly appreciated.

Regards,
KD

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Conditional Formating with colour PaulC Excel Programming 0 September 22nd 09 12:00 AM
conditional formating If A1 or B1 is blank then C1 (Font Colour Ch Adeel Excel Worksheet Functions 7 September 18th 08 11:16 AM
copy rows based on cell colour by conditional formating K[_2_] Excel Programming 8 December 15th 07 07:18 PM
Conditional Formating - Different row color also when using filter Steen Excel Discussion (Misc queries) 5 January 3rd 07 10:56 PM
Excel - conditional formating on graphs. Change colour on a value Peter Shore Charts and Charting in Excel 5 June 9th 06 06:10 AM


All times are GMT +1. The time now is 06:40 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"