Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Just a question regarding a formula operator.

Hi.

I've recently been introduced to the following formula
through Newsgroups:
=SUMPRODUCT(--(Sheet1!$B$2:$B$9000=1),--(Sheet1!
$C$2:$C$9000=14))

It works for my needs, however, I'm trying to understand
it for other applications.

What do the -- operators do? I've never seen them before
and can't find a reference.

Thanks!!

Todd
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default Just a question regarding a formula operator.

The unary minus (-) operator negates values (positive to negative,
negative to positive). Using two in a row restores the sign.

As with any math operator, XL tries to coerce operands to numeric
form if it can. With TRUE/FALSE, XL coerces them to 1/0,
respectively, so

--TRUE == --(1) == -(-1) == 1

--FALSE == --(0) == -(-0) == 0

You could accomplish the same thing with

TRUE + 0 == (1) + 0 == 1

but double unary minus seems to be a bit faster and has a higher
precedence.

In article ,
"Todd S" wrote:

I've recently been introduced to the following formula
through Newsgroups:
=SUMPRODUCT(--(Sheet1!$B$2:$B$9000=1),--(Sheet1!
$C$2:$C$9000=14))

It works for my needs, however, I'm trying to understand
it for other applications.

What do the -- operators do? I've never seen them before
and can't find a reference.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Just a question regarding a formula operator.

Sheet1!$B$2:$B$9000 returns an array of Boolean values (True or False).

applying a math operation to these values converts them to numbers. the
first negative sign converts them to negative numbers and the second
converts them back to positive numbers.


Then sumproduct multiplies the arrays of 1's and 0's together - anywhere you
multiply 1 x 1 you get a 1 otherwise a 0. It then adds these up and gives
you the count of rows matching both positions.

you could do a single conversion for each column in this case since
multiplication of two negatives will produce a positive:

=SUMPRODUCT(-(Sheet1!$B$2:$B$9000=1),-(Sheet1! $C$2:$C$9000=14))

--
Regards,
Tom Ogilvy


"Todd S" wrote in message
...
Hi.

I've recently been introduced to the following formula
through Newsgroups:
=SUMPRODUCT(--(Sheet1!$B$2:$B$9000=1),--(Sheet1!
$C$2:$C$9000=14))

It works for my needs, however, I'm trying to understand
it for other applications.

What do the -- operators do? I've never seen them before
and can't find a reference.

Thanks!!

Todd



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
IF formula-simple question; simple operator Rich D Excel Discussion (Misc queries) 4 December 6th 07 03:36 PM
Operator Question James[_4_] Excel Discussion (Misc queries) 2 December 4th 07 08:32 PM
What does ^ operator mean in a formula?? Vytau Excel Worksheet Functions 2 November 30th 07 10:31 PM
What does ! mean as an operator within a formula Tam Excel Discussion (Misc queries) 3 January 2nd 06 08:48 AM
"--" operator in a formula Arla M Excel Worksheet Functions 2 February 8th 05 09:24 AM


All times are GMT +1. The time now is 11:26 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"