Consulting

Results 1 to 11 of 11

Thread: -- in a formula

  1. #1

    -- in a formula

    Hi,
    These two formulas give the same result, both of which are correct. They sum the Odd numbers in a Defined Range. The only difference is the -- in the second one. Whats it for, or whats it do? Anything?

    =SUMPRODUCT((MOD(COLUMN(NumberRange),2)=1)*NumberRange)
    =SUMPRODUCT(--(MOD(COLUMN(NumberRange),2)=1)*NumberRange)
    Dave
    "The game is afoot Watson"

  2. #2
    Mac Moderator VBAX Expert shades's Avatar
    Joined
    May 2004
    Location
    Kansas City, USA
    Posts
    638
    Location
    Howdy. It coerces Excel to recognize it as a numerical value.

    Software: LibreOffice 3.3 on Mac OS X 10.6.5
    (retired Excel 2003 user, 3.28.2008 )
    Humanware: Older than dirt
    --------------------
    old, slow, and confused
    but at least I'm inconsistent!

    Rich

  3. #3
    VBAX Expert
    Joined
    Feb 2005
    Posts
    929
    Location
    Dave: what is the significance of your Sherlockian reference?
    "It's not just the due date that's important, it's also the do date" [MWE]

    When your problem has been resolved, mark the thread SOLVED by clicking on the Thread Tools dropdown menu at the top of the thread.

  4. #4
    Shades,
    Thx for the reply. I am old and slow also, so i guess i can use that as an excuse. What would be the alternative if its not a numerical value. Its summing numbers & the number thats returned from both can be used in another formula, so wouldn't that be a numerical value?
    Quote Originally Posted by shades
    Howdy. It coerces Excel to recognize it as a numerical value.
    Well MWE,
    Sherlock is one of my heros,
    Sherlock Holmes and Doctor Watson
    221b Baker Street
    London, England
    Fog, Cobblestone streets, Horse dawn carriages, The Hat, The Cloche, The pipe, The magnifying glass, Fuddling Dr Watson.
    The whole thing.

    I'm particulary fond of the Basil Rathbone black & white films. Watch every one i can find one.

    Quote Originally Posted by MWE
    Dave: what is the significance of your Sherlockian reference?
    Dave
    "The game is afoot Watson"

  5. #5
    VBAX Expert
    Joined
    Feb 2005
    Posts
    929
    Location
    Quote Originally Posted by Piranha
    ...
    Well MWE,
    Sherlock is one of my heros,
    Sherlock Holmes and Doctor Watson
    221b Baker Street
    London, England
    Fog, Cobblestone streets, Horse dawn carriages, The Hat, The Cloche, The pipe, The magnifying glass, Fuddling Dr Watson.
    The whole thing.

    I'm particulary fond of the Basil Rathbone black & white films. Watch every one i can find one.
    exactly as I hoped. I too have a great interest in The Great Detective. At one time it was close to an obsession; I belonged to a dozen scion orgns; collected everything available; my license plate was KCOLREHS. I even went to England just to visit the "special places". But my interest has mellowed a bit in the last few years and is now more controlled.

    Rathbone certainly was an excellent Holmes. Nigel Bruce was entertaining, but not a very faithful portrayal of Dr. Watson. I suspect that those films were influenced by the "hero/sidekick" genre that was so popular in the 30's and 40's. Personally, I like the more recent Dr Watsons in the PBS/BBC series of a few years ago.
    "It's not just the due date that's important, it's also the do date" [MWE]

    When your problem has been resolved, mark the thread SOLVED by clicking on the Thread Tools dropdown menu at the top of the thread.

  6. #6
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    Hi Piranha,

    Using -- is one of several ways of coercing non-numeric values (e.g. a Boolean True/False - which is what you have with MOD(etc)=1) to numeric ones should it be required. Multiplication should also have the same effect so the -- is overkill in your case.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by TonyJollans
    Hi Piranha,

    Using -- is one of several ways of coercing non-numeric values (e.g. a Boolean True/False - which is what you have with MOD(etc)=1) to numeric ones should it be required. Multiplication should also have the same effect so the -- is overkill in your case.
    It is not the double unary that is overkill, it is the *. It is NEVER necessary to coerce a number range.

    Piranha, see http://www.xldynamic.com/source/xld.SUMPRODUCT.html
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  8. #8
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    (MOD(COLUMN(NumberRange),2)=1) is an array of Booleans and needs coercing to numeric.

    Of course in this particular case, the array of numerics MOD(COLUMN(NumberRange),2) has effectively been coerced to booleans in the first place by the =1.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  9. #9
    Tony,
    Thx, i am having trouble getting my head around this simple thingy.
    thx for your explanation.
    Quote Originally Posted by TonyJollans
    Hi Piranha,
    Using -- is one of several ways of coercing non-numeric values (e.g. a Boolean True/False - which is what you have with MOD(etc)=1) to numeric ones should it be required. Multiplication should also have the same effect so the -- is overkill in your case.
    xld,
    thx for the site and the.
    Quote Originally Posted by xld
    It is not the double unary that is overkill, it is the *. It is NEVER necessary to coerce a number range.

    Piranha, see http://www.xldynamic.com/source/xld.SUMPRODUCT.htmlYesterday 09:37 PM
    MWE,
    Yeah you may be a little possessed
    Going to England is something i have only to dream about, Your lucky. I havn't seen this, that you refer to. I will look for them.
    Quote Originally Posted by MWE
    I like the more recent Dr Watsons in the PBS/BBC series of a few years ago.
    Dave
    "The game is afoot Watson"

  10. #10
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by TonyJollans
    (MOD(COLUMN(NumberRange),2)=1) is an array of Booleans and needs coercing to numeric.
    Exactly, but NumberRange is not an array of booleans, so there is no need to use * to coerce two arrays as * does. Another operator should be used IMO on the conditional test, either --, +0, 0+, 1*,*1,1^,^1, but not the * operator as that is forcing the formula to do something that SUMPRODUCT does anyway, multiplying arrays of numbers, and thence makes SUMPRODUCT redundant. Formulae should be use the capabilities of a function, else why use it, it becomes an overhead?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  11. #11
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    Sorry, xld, I misinterpreted your post. I know there is much debate about the various ways of doing this. As a rule of thumb I like things to be as obvious as possible over and above other considerations - unfortunately coercion rarely is, no matter how you do it.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •