Solved

VBA to return the details of condtional formatting

Posted on 2014-09-22
1
134 Views
Last Modified: 2014-09-23
I have two questions,

is it possible to have a vba code that lists all of the condtional formatting range and its condtional formula in a workbook?

secondly, how to set condtional formatting using vba.

for example in SELECTION OF range A1:A20  i want to set the formula =COUNTIFS($B$1:$B$20,$A1) in the condtional formatting to highlight it in yellow if the condtion is met.

appreciate your help.
0
Comment
Question by:ProfessorJimJam
1 Comment
 
LVL 43

Accepted Solution

by:
Steve Knight earned 500 total points
ID: 40338440
Sure, something like this should do it... if it has to work with existing conditional formatting entries or not you might not need/want to clear existing conditions etc.

Steve

 
With Range("A1:A20")
        .FormatConditions.Delete
        .FormatConditions.Add Type:=xlExpression, Formula1:="=COUNTIFS($B$1:$B$20,$A1)"
        .FormatConditions(1).SetFirstPriority
        .FormatConditions(1).Interior.Color = 65535
        .FormatConditions(1).StopIfTrue = False
    End With

Open in new window


For Each objFC In Range("A1:A20").FormatConditions
       Debug.Print objFC.Type, objFC.Interior.Color, objFC.Formula1
Next

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now