Solved

VBA to return the details of condtional formatting

Posted on 2014-09-22
1
137 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

821 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