Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Formula vs. Constant

20 views
Skip to first unread message

rk0909

unread,
Jan 12, 2010, 8:27:01 PM1/12/10
to
Is there a way using excel funtions (not UDF) to find if a cell contains a
formula vs. a number (constant).
I looked around the forum but did not find anything. I tried using cell
function and left function but they return the value in the formula itself.
Any help is appreciated.
Regards,
RK

FSt1

unread,
Jan 12, 2010, 8:41:02 PM1/12/10
to
hi
you might consider the goto function.
press F5. click the special button bottom right.
check formula then ok. excel will high light all formulas.
you can do the same with constrants.

regards
FSt1

rk0909

unread,
Jan 12, 2010, 8:46:01 PM1/12/10
to
thanks but i need a function so i can use it in a formula setting.
regards,
RK

Joe User

unread,
Jan 12, 2010, 11:39:01 PM1/12/10
to
"rk0909" wrote:
> thanks but i need a function so i can use it
> in a formula setting.

I don't believe there is any Excel function that distinguishes between a
formula and a constant in another cell.

But then again, I cannot imagine why you would need to make that distinction
in an Excel formula per se, other than some kind of internal validation.

Perhaps if you tell us the real problem you want to solve, we might be able
to offer viable solutions using Excel functions per se.


----- original message -----

T. Valko

unread,
Jan 13, 2010, 12:19:48 AM1/13/10
to
>thanks but i need a function so i can use it in a formula setting.

You can do this without VBA code but it depends on how you intend to use
it/do it.

Do you want to identify cells that contain formulas and highlight them with
conditional formatting? Or, some other use?

Need more details.

--
Biff
Microsoft Excel MVP


"rk0909" <rk0...@discussions.microsoft.com> wrote in message
news:619828B8-0BBF-47F1...@microsoft.com...

Joe User

unread,
Jan 13, 2010, 12:30:45 AM1/13/10
to
"T. Valko" <biffi...@comcast.net> wrote:
> > i need a function so i can use it in a formula setting.
>
> You can do this without VBA code but it depends on how you
> intend to use it/do it.

Biff, regardless of RK's answer, could you explain what you have in mind,
for my edification.


----- original message -----

"T. Valko" <biffi...@comcast.net> wrote in message
news:%23rxFJAB...@TK2MSFTNGP04.phx.gbl...

T. Valko

unread,
Jan 13, 2010, 12:49:54 AM1/13/10
to
You can use the Excel macro function GET.CELL.

See this:

http://groups.google.com/group/microsoft.public.excel.misc/browse_thread/thread/6bf323d2cf859ecd?tvc=2

--
Biff
Microsoft Excel MVP


"Joe User" <joeu2004> wrote in message
news:uhmrPGBl...@TK2MSFTNGP05.phx.gbl...

Joe User

unread,
Jan 13, 2010, 1:10:17 AM1/13/10
to
"T. Valko" <biffi...@comcast.net> wrote:
> You can use the Excel macro function GET.CELL.

Does not seem to work in my version of Excel 2003 (SP3).

Is that an XL2007-ism?


----- original message -----

"T. Valko" <biffi...@comcast.net> wrote in message

news:el%23p7QBl...@TK2MSFTNGP02.phx.gbl...

T. Valko

unread,
Jan 13, 2010, 1:46:30 AM1/13/10
to
Works for me in both Excel 2002, 2007

--
Biff
Microsoft Excel MVP


"Joe User" <joeu2004> wrote in message

news:%231siVcB...@TK2MSFTNGP02.phx.gbl...

Bob Phillips

unread,
Jan 13, 2010, 4:19:37 AM1/13/10
to
It works perfectly well in Excel 2003 (11.8316.8221) SP3.

Problem with that approach is that you have to create a defined name to hold
the GET.CELL function, and you cannot pass a cell reference to a defined
name (well you can, but I find it far too difficult to setup and it is
flaky), you have to hardcode that cell into the formula in the name. This
does provide a little flexibility if you use relative cell addressing but
nowhere near enough that you get with a UDF.

The best way IMO is to wrap it as XLM, although the OP may consider this as
no more than VBA

GetCell
=ARGUMENT("Ref",8)
=ARGUMENT("Type",1)
=RETURN(GET.CELL(Type,Ref))
=RETURN()

and call like

=GetCell(A1,48)

HTH

Bob


"Joe User" <joeu2004> wrote in message

news:%231siVcB...@TK2MSFTNGP02.phx.gbl...

Bernd P

unread,
Jan 13, 2010, 5:06:54 AM1/13/10
to
Hello,

You can use Get.Cell:
http://sulprobil.com/html/get_cell.html

Regards,
Bernd

Lori Miller

unread,
Jan 13, 2010, 8:17:02 AM1/13/10
to
Instead of the udf =IsFormula(A1), you can enter

=IF(1,IsFormula,A1)

and define the name "IsFormula" to refer to:

=GET.CELL(48,TEXTREF(REPLACE(GET.FORMULA(TEXTREF("rc")),1,5,"if(")))

It's a bit convoluted but not too flaky :)


"Bob Phillips" wrote:

> .
>

Bob Phillips

unread,
Jan 13, 2010, 8:47:01 AM1/13/10
to
That is so cute. Excellent stuff!

Bob

"Lori Miller" <LoriM...@discussions.microsoft.com> wrote in message
news:8237A724-3B34-4001...@microsoft.com...

Joe User

unread,
Jan 13, 2010, 9:47:57 AM1/13/10
to
"Bob Phillips" <bob.ph...@somewhere.com> wrote:
> It works perfectly well in Excel 2003 (11.8316.8221) SP3.
> Problem with that approach is that you have to create a
> defined name to hold the GET.CELL function

Yup! That was my mistake: not following Biff's instruction to the letter.

First, I tried GET.CELL directly in a formula instead of creating the named
formula. Second, I neglected to select A1 before using the relative
reference A1 in the named formula.

But I don't find the relative reference very practical for RK's purpose,
namely to use in a formula unless you deviate from Biff's instructions. For
example, selecting B1 and defining the named formula =GET.CELL(48,A1)
permits us to apply the named formula to any cell to the left.

Perhaps Lori's approach is more flexible. I haven't tried it.


----- original message -----

"Bob Phillips" <bob.ph...@somewhere.com> wrote in message
news:%23MzUKGD...@TK2MSFTNGP02.phx.gbl...

Bob Phillips

unread,
Jan 13, 2010, 9:52:25 AM1/13/10
to

"Joe User" <joeu2004> wrote in message
news:u$Uvm9FlK...@TK2MSFTNGP02.phx.gbl...
> "Bob Phillips" <bob.ph...@somewhere.com> wrote:


> But I don't find the relative reference very practical for RK's purpose,
> namely to use in a formula unless you deviate from Biff's instructions.
> For example, selecting B1 and defining the named formula =GET.CELL(48,A1)
> permits us to apply the named formula to any cell to the left.

It isn't as I pointed out earlier. My XLM macro is far better ... but


> Perhaps Lori's approach is more flexible. I haven't tried it.

It is, it is sheer brilliance.


Lori Miller

unread,
Jan 13, 2010, 11:27:22 AM1/13/10
to
Thanks Bob, happy to share it. But the main credit should
go to JK Pieterse who i believe had the underlying idea.

A more general approach is: =CHOOSE(1,Get.Cell,48,A1)

Get.Cell: =GET.CELL(EVALUATE(REPLACE(GET.CELL(6,TEXTREF("rc"))
,1,9,"choose(2")),EVALUATE(REPLACE(GET.CELL(6,TEXTREF("rc"))
,1,9,"choose(3")))

"Bob Phillips" <bob.ph...@somewhere.com> wrote in message

news:uURjlbFl...@TK2MSFTNGP06.phx.gbl...

T. Valko

unread,
Jan 13, 2010, 12:38:45 PM1/13/10
to
Excellent!

That solves the problem of passing a relative cell ref as Bob noted.

Now I just have to figure out how it works! Not familiar with TEXTREF. I do
have the macrofun help file but I guess I'll have to read it about 10 times
before I understand.

--
Biff
Microsoft Excel MVP

"Lori Miller" <LoriM...@discussions.microsoft.com> wrote in message
news:8237A724-3B34-4001...@microsoft.com...

Bob Phillips

unread,
Jan 13, 2010, 2:50:49 PM1/13/10
to
I get all of it ... except the bit where it replaces the first 5 characters,
=IF(1, by IF(.

Why does it do that Lori?

Bob

"T. Valko" <biffi...@comcast.net> wrote in message

news:%23zKICdH...@TK2MSFTNGP05.phx.gbl...

rk0909

unread,
Jan 13, 2010, 7:27:01 PM1/13/10
to

thanks for all the posts. The problem at hand is:

Col C Col D Col F
6 India 100
6 Germany Need a formula which averages all of col F with 6
in Col C and Germany in Col D
3 China 50
6 Germany Need a formula which averages all of col F with
6 in Col C and Germany in Col D

so i was thinking if there was a way to identfy cells with formula vs.
constant i could use sumifs to avoid circularity.

thanks,

RK
"Bernd P" wrote:

> .
>

T. Valko

unread,
Jan 13, 2010, 7:39:09 PM1/13/10
to
I'm also having a hard time trying to figure that out.

An alternative that seems a bit easier to understand:

IsFormula
Refers to:

=GET.CELL(48,TEXTREF(SUBSTITUTE(MID(GET.FORMULA(TEXTREF("rc")),17,100),")","")))

It looks like TEXTREF is somewhat similar to INDIRECT.

To those who might be following this thread, the basic idea is that the 2
two formulas are essentially a "circular reference" between the 2 formulas.

If C1 contains this formula:

=IF(1,IsFormula,AB200)

TEXTREF(SUBSTITUTE(MID(GET.FORMULA(TEXTREF("rc")),17,100),")","")) "simply"
extracts the cell ref from the formula in C1 and passes that cell ref to
GET.CELL as a relative R1C1 reference.

The whole trick to getting this to work is coming up with a simple enough
formula like =IF(1,IsFormula,AB200) that can be taken apart to get the cell
reference yet at the same time make some logical sense to the user as to
what the formula is intended to do.

Thank you Lori for giving me a reason to tinker with this!

See, you learn something new every day.

--
Biff
Microsoft Excel MVP

"Bob Phillips" <bob.ph...@somewhere.com> wrote in message

news:OH0T6mIl...@TK2MSFTNGP06.phx.gbl...

T. Valko

unread,
Jan 13, 2010, 9:43:22 PM1/13/10
to
Not sure I'm following you.

This is not a problem if you put the formula **outside** of the referenced
ranges. For example, this array formula** :

=AVERAGE(IF(C1:C10=6,IF(D1:D10="Germany",F1:F10)))

** array formulas need to be entered using the key combination of
CTRL,SHIFT,ENTER (not just ENTER). Hold down both the CTRL key and the SHIFT
key then hit ENTER.

As long as you don't enter that formula anywhere within C1:D10, F1:F10 it
will do what you want.

--
Biff
Microsoft Excel MVP


"rk0909" <rk0...@discussions.microsoft.com> wrote in message

news:4395BEF8-1ED2-4338...@microsoft.com...

rk0909

unread,
Jan 13, 2010, 10:32:01 PM1/13/10
to
thanks again. However, this formula needs to be applied in the range itself
and hats why I am getting a circular reference. This needs to be applied to
a large matrix so I wanted to do it within the range itself and not create a
separate range.
thanks again for prompt responses.
RK

"T. Valko" wrote:

> .
>

Joe User

unread,
Jan 13, 2010, 11:15:01 PM1/13/10
to
"rk0909" wrote:
> thanks again. However, this formula needs to be
> applied in the range itself and hats why I am getting
> a circular reference.
[....]

> > > Need a formula which averages all of col F with
> > > 6 in Col C and Germany in Col D

....And you want the average formula to be in a cell somewhere in the middle
of, say column F?

Would one of the following approaches work for you?

Suppose the data are in rows 1 through 100, and you want the average formula
in row 50. Then try either of the following array formulas [*]:


1.
=average(if(c1:c49=6,if(d1:d49="Germany",f1:f49)),
if(c51:c100=6,if(d51:d100="Germany",f51:f100)))

The ranges should adjust automagically if you insert or delete rows above
and below the cell with this formula.


2. Under Tools > Options > Calculation (in Excel 2003), set the Iteration
option and Maximum Iterations to 1. Then:

=average(if(c1:c100=6,if(d1:d100="Germany",f1:f100)))


Again, an array formula is committed by pressing ctrl+shift+Enter instead of
just Enter. You should see curly braces around the entire formula in the
Formula Bar, viz. {=formula}. But you should not type the curly braces
yourself. If you make a mistake, select the cell and press F2, make
modifications if any, then press ctrl+shift+Enter.


----- original message -----

Lori Miller

unread,
Jan 14, 2010, 4:46:09 AM1/14/10
to
In response to your questions...

TEXTREF is like INDIRECT but also evaluates expressions
in RC notation. The idea is to change 1 to 0 and evaluate:
IF(0,IsFormula,A1) for use in the second argument of Get.Cell.
Since null arguments evaluate to 0 you can omit the 0 in IF().

Similarly the second approach evaluates:
choose(2,Get.Cell,48,A1) and choose(3,Get.Cell,48,A1)
for use in both Get.Cell arguments.

As you probably know for debugging you can open an Excel4
Macro sheet and enter these expressions using the formula
wizard then press ctrl+` to change to values.

Another application is for evaluating expressions.
Define a name "Evaluate" to refer to:
=EVALUATE(EVALUATE(REPLACE(GET.CELL(6,TEXTREF("rc")),1,5,"if(")))
then you can try things like:
=IF(1,Evaluate,"sum("&A1&")")
where A1 contains comma separated values.

As Biff says, this is really aimed at users for exposing macro
functionality without udfs. Udfs make more sense from a
developer standpoint:

Function GetCell(Type_Num As Integer, Reference As Range) As Variant
GetCell = ExecuteExcel4Macro("get.cell(" & Type_Num & _
"," & Reference.Address(True, True, xlR1C1, True) & ")")
End Function


"T. Valko" <biffi...@comcast.net> wrote in message

news:e%23q48HLl...@TK2MSFTNGP04.phx.gbl...

rk0909

unread,
Jan 14, 2010, 1:34:01 PM1/14/10
to
this works if there I use only one formula per column. If there are more
than one cells where i need to insert this formula, I get circ reference. Is
there a way to structure the If statement that skips the cells with formulas
or zeros. Then I can average across without getting into the circ problem.
thanks again for all your help.
0 new messages