[VBA] A function that returns the color of an active MFC

Last update on January 8, 2009 10:48 AM by jak58
Published by jak58

[VBA] A function that returns the color of an active MFC








This function returns the value of the active format in conditional formatting.
With the function below, two values can be returned.
Mode = 0: the value of Interior.ColorIndex
Mode = 1: the value of Interior.Color


With some changes but all other properties can be returned.



Public Function ColorMFC(RG As Range, Optional Mode As Byte = 0) As Variant
Dim e As Long, i As Byte, LoTest As Boolean
Dim LoMFC As FormatCondition
    Application.Volatile
    'loop depending on condition(s)
    'if there is no MFC .FormatConditions.Count return 0
    For i = 1 To RG.FormatConditions.Count
        Set LoMFC = RG.FormatConditions(i)
        If LoMFC.Type = xlCellValue Then
        'test the type of formula entered'
            Select Case LoMFC.Operator
            Case xlEqual
                LoTest = RG = Evaluate(LoMFC.Formula1)
            Case xlNotEqual
                LoTest = RG <> Evaluate(LoMFC.Formula1)
            Case xlGreater
                LoTest = RG > Evaluate(LoMFC.Formula1)
            Case xlGreaterEqual
                LoTest = RG >= Evaluate(LoMFC.Formula1)
            Case xlLess
                LoTest = RG < Evaluate(LoMFC.Formula1)
            Case xlLessEqual
                LoTest = RG <= Evaluate(LoMFC.Formula1)
            Case xlNotBetween
                LoTest = (RG < Evaluate(LoMFC.Formula1) Or RG > Evaluate(LoMFC.Formula2))
            Case xlBetween
                LoTest = (RG >= Evaluate(LoMFC.Formula1)) And (RG <= Evaluate(LoMFC.Formula2))
            End Select
            If LoTest Then
                'Add another format if necessary,
                'Border, font, policy etc..
                Select Case Mode
                Case 0
                    ColorMFC = LoMFC.Interior.ColorIndex
                Case 1
                    ColorMFC = LoMFC.Interior.Color
                End Select
                Exit Function
            End If
        End If
    Next i
    ColorMFC = 0
End Function


The formula:

=ColorMFC(A2)

The MFC can be with a direct or indirect value (the contents of another cell)
Ex 1 : >1 and <10 
Ex 2 : >=D10 and <=E10
Best answers for « A function that returns the color of an active MFC » in :
Spreadsheets - Mathematical Functions Show Standard Functions Function Description ABS() This function returns the absolute value of a number. It therefore returns the number, if it is positive, or the opposite (positive) if it is negative ODD(value) Rounds a number up to the...
VB6 Finding the RGB values of a color ShowVB6 Finding the RGB values of a color Dim R as integer Dim G as integer Dim B as integer Sub FindRGB(Col As Long) R = &HFF& And Col G = (&HFF00& And Col ) \ 256 B = (&HFF0000 And Col ) \ 65536 End Sub Note: Here...
Windows Processes ShowWindows Processes Csrss.exe Explorer.exe Lsass.exe Mstask.exe Smss.exe Spoolsv.exe Svchost.exe rtvscan.exe System System Idle Process Winlogon.exe Winmgmt.exe Windows processes Process Explorer
Activate mail ()function on website ShowActivate mail function on website To be able to activate the mail function on your website, there is a special code that you can make use of and paste in your PHP document. Some webhosting services do not allow them however. You should...
Download Active Phone Server ShowDescription The application is designed by SoftCab, Inc. So far this application is well known worldwide for its perfection. It has won awards in certain places and it is being used by companies also. Active Phone Server is an application based on...
Download Active Desktop Calendar ShowActive Desktop Calendar is a calendar which integrates into Windows’ desktop. It is completely customizable and integrates into: - the calendar of Google, - ICS file web, - Outlook to display your meetings and tasks on the desktop. It...
Spreadsheet - Functions ShowThe Concept of a Function Spreadsheets generally have a large number of integrated functions for processing data. There are hundreds, categorised as follows: Arithmetic functions that offer basic tools to process numerical data Statistical...
E-Procurement - Management of the purchasing function Showe-Procurement The term "e-Procurement" (for Electronic Procurement, sometimes written eprocurement) refers to the use of new technologies to automate and optimize the purchasing function of the company. The term refers to a B2B exchange, i.e. a...
Spreadsheets - Arithmetic Functions ShowThe Concept of a Function Spreadsheets generally have a large number of integrated functions for processing data. There are hundreds, categorised as follows: Arithmetic functions that offer basic tools to process numerical data Statistical...