PC Review


Reply
Thread Tools Rate Thread

Conditional format if cell contains formula

 
 
Jean-Marc
Guest
Posts: n/a
 
      14th Aug 2008
Is there a way (conditional formatting?) to apply a different format to cells
that contain a formula, as opposed to cells that have a directly entered
value?
 
Reply With Quote
 
 
 
 
Yong Heng
Guest
Posts: n/a
 
      14th Aug 2008
sure.

here's an example

A B C D E F G
1 no1 no2 no3 no4 no5 no6
2 ticket1 2 15 26 27 36 38
3 ticket2 1 12 13 15 24 34
4 ticket3 3 5 20 28 37 40
5
6 drawn 3 15 25 26 47 49

1. Select cells B2:G4
2. Select Conditional Formatting
3. Choose Formula Is (as opposed to Cell value is)
4. For the formula, use the CountIf function:
=COUNTIF($B$6:$G$6,B2)
5. Click the Format button.
6. Select formatting options (choose a color for the cell), click OK

What happens is that the conditional formatting formula will evaluate each
cell to see if it should "count" according to the criteria. Once it is
"counted", it will apply the format to the cell.

Try it, its fun.

Yong Heng


"Jean-Marc" wrote:

> Is there a way (conditional formatting?) to apply a different format to cells
> that contain a formula, as opposed to cells that have a directly entered
> value?

 
Reply With Quote
 
Jean-Marc
Guest
Posts: n/a
 
      14th Aug 2008
Thanks, but you misunderstood my question. I am familiar with the operation
of conditional formats. Here is a simple example of what I want to achieve:
Cell A1 contains value '1'
Cell A2 contains value '2'
Cell A3 contains formula '=SUM(A1:A2)'

Now what I would like is for cell A3 to be shown on a blue background,
because it is a formula, whilst cells A1 and A2 should remain in the default
format, because they are manually entered values. Basically is there an Excel
function that is able to detect whether a cell is a formula or a single
value? In other words, if the cell entry starts with '=', then I would like
it to be formatted differently. Sounds easy, but I am stumped. Excel seems to
only consider the *Value* in a cell, but not whether that value comes from a
manual entry or a formula calculation.

"Yong Heng" wrote:

> sure.
>
> here's an example
>
> A B C D E F G
> 1 no1 no2 no3 no4 no5 no6
> 2 ticket1 2 15 26 27 36 38
> 3 ticket2 1 12 13 15 24 34
> 4 ticket3 3 5 20 28 37 40
> 5
> 6 drawn 3 15 25 26 47 49
>
> 1. Select cells B2:G4
> 2. Select Conditional Formatting
> 3. Choose Formula Is (as opposed to Cell value is)
> 4. For the formula, use the CountIf function:
> =COUNTIF($B$6:$G$6,B2)
> 5. Click the Format button.
> 6. Select formatting options (choose a color for the cell), click OK
>
> What happens is that the conditional formatting formula will evaluate each
> cell to see if it should "count" according to the criteria. Once it is
> "counted", it will apply the format to the cell.
>
> Try it, its fun.
>
> Yong Heng
>
>
> "Jean-Marc" wrote:
>
> > Is there a way (conditional formatting?) to apply a different format to cells
> > that contain a formula, as opposed to cells that have a directly entered
> > value?

 
Reply With Quote
 
Peo Sjoblom
Guest
Posts: n/a
 
      14th Aug 2008
You can use Excel 4 macro in a defined name formula to check if cell has a
formula, using you example
do insert>name>define, in the source box put

=GET.CELL(6,Sheet1!$A1)

and in the name box type in something descriptive like

FormulaIs

click OK


Select A1:A3
with A1 as the active cell, do format>conditional formatting, select formula
is
and use

=LEFT(FormulaIs)="="

or in a pedagogic manner

=LEFT(FormulaIs,1)="="

you can actually leave out 1 if you just want one character

now click the format button and select format and click OK twice


--


Regards,


Peo Sjoblom





"Jean-Marc" <(E-Mail Removed)> wrote in message
news:B6B1DC0C-6046-4022-A7BF-(E-Mail Removed)...
> Thanks, but you misunderstood my question. I am familiar with the
> operation
> of conditional formats. Here is a simple example of what I want to
> achieve:
> Cell A1 contains value '1'
> Cell A2 contains value '2'
> Cell A3 contains formula '=SUM(A1:A2)'
>
> Now what I would like is for cell A3 to be shown on a blue background,
> because it is a formula, whilst cells A1 and A2 should remain in the
> default
> format, because they are manually entered values. Basically is there an
> Excel
> function that is able to detect whether a cell is a formula or a single
> value? In other words, if the cell entry starts with '=', then I would
> like
> it to be formatted differently. Sounds easy, but I am stumped. Excel seems
> to
> only consider the *Value* in a cell, but not whether that value comes from
> a
> manual entry or a formula calculation.
>
> "Yong Heng" wrote:
>
>> sure.
>>
>> here's an example
>>
>> A B C D E F G
>> 1 no1 no2 no3 no4 no5 no6
>> 2 ticket1 2 15 26 27 36 38
>> 3 ticket2 1 12 13 15 24 34
>> 4 ticket3 3 5 20 28 37 40
>> 5
>> 6 drawn 3 15 25 26 47 49
>>
>> 1. Select cells B2:G4
>> 2. Select Conditional Formatting
>> 3. Choose Formula Is (as opposed to Cell value is)
>> 4. For the formula, use the CountIf function:
>> =COUNTIF($B$6:$G$6,B2)
>> 5. Click the Format button.
>> 6. Select formatting options (choose a color for the cell), click OK
>>
>> What happens is that the conditional formatting formula will evaluate
>> each
>> cell to see if it should "count" according to the criteria. Once it is
>> "counted", it will apply the format to the cell.
>>
>> Try it, its fun.
>>
>> Yong Heng
>>
>>
>> "Jean-Marc" wrote:
>>
>> > Is there a way (conditional formatting?) to apply a different format to
>> > cells
>> > that contain a formula, as opposed to cells that have a directly
>> > entered
>> > value?



 
Reply With Quote
 
Jean-Marc
Guest
Posts: n/a
 
      14th Aug 2008
Excellent - works great. Thanks. You are a guru.

"Peo Sjoblom" wrote:

> You can use Excel 4 macro in a defined name formula to check if cell has a
> formula, using you example
> do insert>name>define, in the source box put
>
> =GET.CELL(6,Sheet1!$A1)
>
> and in the name box type in something descriptive like
>
> FormulaIs
>
> click OK
>
>
> Select A1:A3
> with A1 as the active cell, do format>conditional formatting, select formula
> is
> and use
>
> =LEFT(FormulaIs)="="
>
> or in a pedagogic manner
>
> =LEFT(FormulaIs,1)="="
>
> you can actually leave out 1 if you just want one character
>
> now click the format button and select format and click OK twice
>
>
> --
>
>
> Regards,
>
>
> Peo Sjoblom
>
>
>
>
>
> "Jean-Marc" <(E-Mail Removed)> wrote in message
> news:B6B1DC0C-6046-4022-A7BF-(E-Mail Removed)...
> > Thanks, but you misunderstood my question. I am familiar with the
> > operation
> > of conditional formats. Here is a simple example of what I want to
> > achieve:
> > Cell A1 contains value '1'
> > Cell A2 contains value '2'
> > Cell A3 contains formula '=SUM(A1:A2)'
> >
> > Now what I would like is for cell A3 to be shown on a blue background,
> > because it is a formula, whilst cells A1 and A2 should remain in the
> > default
> > format, because they are manually entered values. Basically is there an
> > Excel
> > function that is able to detect whether a cell is a formula or a single
> > value? In other words, if the cell entry starts with '=', then I would
> > like
> > it to be formatted differently. Sounds easy, but I am stumped. Excel seems
> > to
> > only consider the *Value* in a cell, but not whether that value comes from
> > a
> > manual entry or a formula calculation.
> >
> > "Yong Heng" wrote:
> >
> >> sure.
> >>
> >> here's an example
> >>
> >> A B C D E F G
> >> 1 no1 no2 no3 no4 no5 no6
> >> 2 ticket1 2 15 26 27 36 38
> >> 3 ticket2 1 12 13 15 24 34
> >> 4 ticket3 3 5 20 28 37 40
> >> 5
> >> 6 drawn 3 15 25 26 47 49
> >>
> >> 1. Select cells B2:G4
> >> 2. Select Conditional Formatting
> >> 3. Choose Formula Is (as opposed to Cell value is)
> >> 4. For the formula, use the CountIf function:
> >> =COUNTIF($B$6:$G$6,B2)
> >> 5. Click the Format button.
> >> 6. Select formatting options (choose a color for the cell), click OK
> >>
> >> What happens is that the conditional formatting formula will evaluate
> >> each
> >> cell to see if it should "count" according to the criteria. Once it is
> >> "counted", it will apply the format to the cell.
> >>
> >> Try it, its fun.
> >>
> >> Yong Heng
> >>
> >>
> >> "Jean-Marc" wrote:
> >>
> >> > Is there a way (conditional formatting?) to apply a different format to
> >> > cells
> >> > that contain a formula, as opposed to cells that have a directly
> >> > entered
> >> > value?

>
>
>

 
Reply With Quote
 
T. Valko
Guest
Posts: n/a
 
      14th Aug 2008
You can use a UDF (user defined function):

Function IsFormula(cell_ref As Range)
IsFormula = cell_ref.HasFormula
End Function

To use this:

Open the VBE editor: ALT F11
Open the Project Explorer: CTRL R
Locate your file name in the project explorer pane on the left.
Right click the file name
Select: Insert>Module
Copy the code above and paste into the window on the right
Return back to Excel: ALT Q

Set the conditional formatting...
Select the cell(s) in question. Assume this is cell A1.
Goto Format>Conditional Formatting
Formula Is: =IsFormula(A1)
Click the Format button
Select the desired style(s)
OK out


--
Biff
Microsoft Excel MVP


"Jean-Marc" <Jean-(E-Mail Removed)> wrote in message
news:AAE5A0CC-A25A-4C7A-93E2-(E-Mail Removed)...
> Is there a way (conditional formatting?) to apply a different format to
> cells
> that contain a formula, as opposed to cells that have a directly entered
> value?



 
Reply With Quote
 
Jean-Marc
Guest
Posts: n/a
 
      14th Aug 2008
Thanks. Very elegant solution.

"T. Valko" wrote:

> You can use a UDF (user defined function):
>
> Function IsFormula(cell_ref As Range)
> IsFormula = cell_ref.HasFormula
> End Function
>
> To use this:
>
> Open the VBE editor: ALT F11
> Open the Project Explorer: CTRL R
> Locate your file name in the project explorer pane on the left.
> Right click the file name
> Select: Insert>Module
> Copy the code above and paste into the window on the right
> Return back to Excel: ALT Q
>
> Set the conditional formatting...
> Select the cell(s) in question. Assume this is cell A1.
> Goto Format>Conditional Formatting
> Formula Is: =IsFormula(A1)
> Click the Format button
> Select the desired style(s)
> OK out
>
>
> --
> Biff
> Microsoft Excel MVP
>
>
> "Jean-Marc" <Jean-(E-Mail Removed)> wrote in message
> news:AAE5A0CC-A25A-4C7A-93E2-(E-Mail Removed)...
> > Is there a way (conditional formatting?) to apply a different format to
> > cells
> > that contain a formula, as opposed to cells that have a directly entered
> > value?

>
>
>

 
Reply With Quote
 
T. Valko
Guest
Posts: n/a
 
      14th Aug 2008
You're welcome. Thanks for the feedback!

--
Biff
Microsoft Excel MVP


"Jean-Marc" <(E-Mail Removed)> wrote in message
news:BC1E9874-1DC6-421E-8967-(E-Mail Removed)...
> Thanks. Very elegant solution.
>
> "T. Valko" wrote:
>
>> You can use a UDF (user defined function):
>>
>> Function IsFormula(cell_ref As Range)
>> IsFormula = cell_ref.HasFormula
>> End Function
>>
>> To use this:
>>
>> Open the VBE editor: ALT F11
>> Open the Project Explorer: CTRL R
>> Locate your file name in the project explorer pane on the left.
>> Right click the file name
>> Select: Insert>Module
>> Copy the code above and paste into the window on the right
>> Return back to Excel: ALT Q
>>
>> Set the conditional formatting...
>> Select the cell(s) in question. Assume this is cell A1.
>> Goto Format>Conditional Formatting
>> Formula Is: =IsFormula(A1)
>> Click the Format button
>> Select the desired style(s)
>> OK out
>>
>>
>> --
>> Biff
>> Microsoft Excel MVP
>>
>>
>> "Jean-Marc" <Jean-(E-Mail Removed)> wrote in message
>> news:AAE5A0CC-A25A-4C7A-93E2-(E-Mail Removed)...
>> > Is there a way (conditional formatting?) to apply a different format to
>> > cells
>> > that contain a formula, as opposed to cells that have a directly
>> > entered
>> > value?

>>
>>
>>



 
Reply With Quote
 
Bertus Swanepoel
Guest
Posts: n/a
 
      26th Sep 2008
Hi, I have done this the UDF way, but now excel behaves strangely. I have applied the conditional formatting to cells in Sheet2. If I want to pick up a value from sheet 2 in sheet1 (formula in sheet 1 A1: ='Sheet2'!B6), nothing happend in sheet 1. Instead excel inputs a formula in a random cell in sheet 2 which refers to itself creating a circular reference. When I clear the conditional formatting from sheet 2 all is fine. Has anyone experienced this?
 
Reply With Quote
 
Bertus Swanepoel
Guest
Posts: n/a
 
      26th Sep 2008
Hi, I have done this the UDF way, but now excel behaves strangely. I have applied the conditional formatting to cells in Sheet2. If I want to pick up a value from sheet 2 in sheet1 (formula in sheet 1 A1: ='Sheet2'!B6), nothing happend in sheet 1. Instead excel inputs a formula in a random cell in sheet 2 which refers to itself creating a circular reference. When I clear the conditional formatting from sheet 2 all is fine. Has anyone experienced this? I am working in Excel 2007.

thanks
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to conditional format a cell if the cell contains a formula (U marzomarz Microsoft Excel Worksheet Functions 1 8th Oct 2009 09:55 PM
Conditional Format Based on Formula in Cell cardan Microsoft Excel Programming 1 3rd Sep 2009 11:00 PM
conditional format if the cell contains a formula =?Utf-8?B?ZWxsZWJlbGxl?= Microsoft Excel Worksheet Functions 11 12th Sep 2006 09:04 AM
conditional format if the cell contains a formula =?Utf-8?B?ZWxsZWJlbGxl?= Microsoft Excel Worksheet Functions 0 11th Sep 2006 03:58 PM
How do I do conditional format based on a cell with a formula? =?Utf-8?B?SnVzdGlu?= Microsoft Excel Worksheet Functions 9 17th Dec 2004 02:05 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:28 AM.