+ Reply to Thread
Results 1 to 23 of 23

Formula for returning only positive values from a range

  1. #1
    Registered User
    Join Date
    09-17-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    17

    Question Formula for returning only positive values from a range

    There was an example of formula that returns only positive values from a range in John Walkenbach old book Microsoft Bible 2003.
    (Chapter 15, Working with Multicell Array Formulas). In case all data are stored in column range Data the formula takes the following view:
    =IF(ISERR(SMALL(IF(Data>0;ROW(INDIRECT("1:"&ROWS(Data))));ROW(INDIRECT("1:"&ROWS(Data)))));"";INDEX(Data;SMALL(IF(Data>0;ROW(INDIRECT("1:"&ROWS(Data))));ROW(INDIRECT("1:"&ROWS(Data))))))

    My question is what I need to change in the above formula if Data is not a column range, but a row range?

    I tried to change all ROW to COLUMN and all ROWS to COLUMNS, but that only caused N/A to show up in all cells..

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: Formula for returning only positive values from a range

    Try this
    confirmed with ctrl+shift+enter (not just enter)

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Doesn't matter is your range in row or column.
    Attached Files Attached Files
    Last edited by zbor; 12-28-2014 at 10:10 AM.

  3. #3
    Registered User
    Join Date
    09-17-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Formula for returning only positive values from a range

    Thanks. Is it possible to change somehow the formula so it allows the Data range to be entered explicitly? For instance, by typing C65:J65 instead of Data (I guess ROWS(A$1:A1) must be then changed to ROWS(C$65:C65)?).

    I ask this because my attempt to do so has failed...

  4. #4
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,055

    Re: Formula for returning only positive values from a range

    Leave rows the way it was. it is a simple counter, and needs to start at 1
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  5. #5
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Formula for returning only positive values from a range

    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  6. #6
    Registered User
    Join Date
    09-17-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Formula for returning only positive values from a range

    Quote Originally Posted by Glenn Kennedy View Post
    Leave rows the way it was. it is a simple counter, and needs to start at 1
    It just doesnt work the way I wanted it to. In John WalkenBah's example one can squeeze his formula in whatever column one likes, just by making sure the size of the new selection matches the size of the original range. Is it possible to do the same with the rows?
    Last edited by Novosedoff; 12-28-2014 at 11:26 AM.

  7. #7
    Registered User
    Join Date
    09-17-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Formula for returning only positive values from a range

    Quote Originally Posted by Tony Valko View Post
    Sorry, perhaps I am a little slow. Can you make it a little more obvious for me? What am I supposed to do with the example that does "smth else"?

  8. #8
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: Formula for returning only positive values from a range

    Just change data with desired range:

    Formula: copy to clipboard
    Please Login or Register  to view this content.

  9. #9
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: Formula for returning only positive values from a range

    Just change data with desired range:

    Formula: copy to clipboard
    Please Login or Register  to view this content.

  10. #10
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,055

    Re: Formula for returning only positive values from a range

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

  11. #11
    Registered User
    Join Date
    09-17-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Formula for returning only positive values from a range

    Quote Originally Posted by Glenn Kennedy View Post
    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic
    Here it goes, buddy.

    In red are highlighted the original cells. One has to choose only those that are >0. They must be copied into any of yellow rows.
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    09-17-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Formula for returning only positive values from a range

    Quote Originally Posted by zbor View Post
    Just change data with desired range:

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    By some reason when I use your formula Excel fills all the resultant cells with the same value, i.e. the first non-zero value from the original row. This is wrong.

  13. #13
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: Formula for returning only positive values from a range

    Did you confirmed with ctrl+shift+enter (not just enter)?

    See above attachment where it works.

  14. #14
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,938

    Re: Formula for returning only positive values from a range

    The suggested formula is an ARRAY formula
    ...confirmed by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. You will know the array is active when you see curly braces { } appear around your formula. If you do not CTRL+SHIFT+ENTER you will get an error or a clearly incorrect answer. Press F2 on that cell and try again.
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  15. #15
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Formula for returning only positive values from a range

    if your datarange is say in d1:m1
    or it could be in a1:10
    name the chosen range i used data1
    if you want to extract the lowest non 0
    to cells filled filled across
    =IF(ISERR(SMALL(IF(data1>0,data1),COLUMNS($A:A))),"",SMALL(IF(data1>0,data1),COLUMNS($A:A)))
    if you wanted to fill down
    =IF(ISERR(SMALL(IF(data1>0,data1),ROWS(A$1:A1))),"",SMALL(IF(data1>0,data1),ROWS(A$1:A1)))
    as zbor points out it doesnt matter about the orientation of the named range
    Last edited by martindwilson; 12-28-2014 at 11:47 AM.
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  16. #16
    Registered User
    Join Date
    09-17-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Formula for returning only positive values from a range

    Quote Originally Posted by zbor View Post
    Did you confirmed with ctrl+shift+enter (not just enter)?

    See above attachment where it works.
    Well. I may be a little slow, but not that stupid :-) I know what array formulae in Excel mean and how they are entered.

    Anyway, my problem is not actual any longer. My Russian mates have helped me out with the right answer a little quicker. In case someone needs this in the future, I attach the spreadsheet with the formula that WORKS FINE for me.
    Attached Files Attached Files
    Last edited by Novosedoff; 12-28-2014 at 11:50 AM.

  17. #17
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Formula for returning only positive values from a range

    well if you mentioned that you had excel later than 2003 as shown in your profile we would have all suggested iferror() rather than the repetitive if(isna construct
    Please update your profile as necessary to properly reflect the exact version(s) of Excel your question relates to. Members tailor answers based on your Excel version.

  18. #18
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: Formula for returning only positive values from a range

    oh, I see now what you mean.
    Just change ROWS to COLUMNS

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    It can be shorten with IFERROR formula but your profile states 2003 so I put like that.

    Btw, thanx for sharing your solution too.

  19. #19
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: Formula for returning only positive values from a range

    But here:

    This will return proper solution no matter how your data is orientated (I put bigger range, not just single row or column) and no matter do you pull formula right or down:

    XL2003:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    XL2007+:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  20. #20
    Registered User
    Join Date
    09-17-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Formula for returning only positive values from a range

    In case someone would need in the future there is a more universal solution, which looks as follows

    =IF(ISERR(SMALL(IF(Data>0,TRANSPOSE(ROW(INDIRECT("1:"&COLUMNS(Data))))),TRANSPOSE(ROW(INDIRECT("1:"&COLUMNS(Data)))))),"",INDEX(Data,SMALL(IF(Data>0,TRANSPOSE(ROW(INDIRECT("1:"&COLUMNS(Data))))),TRANSPOSE(ROW(INDIRECT("1:"&COLUMNS(Data)))))))

  21. #21
    Forum Contributor
    Join Date
    12-23-2003
    Posts
    179

    Re: Formula for returning only positive values from a range

    Are you sure that works, i.e. the last one with lots of TRANSPOSE calls? Even if it would, it would be very costly...

    By the way, the formulas you have in the file you uploaded are not robust: Try to insert new columns in front of the data/formula cells to see this.

  22. #22
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Formula for returning only positive values from a range

    Quote Originally Posted by Novosedoff View Post
    In case someone would need in the future there is a more universal solution, which looks as follows

    =IF(ISERR(SMALL(IF(Data>0,TRANSPOSE(ROW(INDIRECT("1:"&COLUMNS(Data))))),TRANSPOSE(ROW(INDIRECT("1:"&COLUMNS(Data)))))),"",INDEX(Data,SMALL(IF(Data>0,TRANSPOSE(ROW(INDIRECT("1:"&COLUMNS(Data))))),TRANSPOSE(ROW(INDIRECT("1:"&COLUMNS(Data)))))))
    I'm not real sure what you're trying to do but looking at that formula I'm certain there has got to be a better way.

  23. #23
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: Formula for returning only positive values from a range

    Quote Originally Posted by Tony Valko View Post
    I'm not real sure what you're trying to do but looking at that formula I'm certain there has got to be a better way.
    Yes, one post above

    Here is also non-array solution (only need to take care of errors depending on version):

    Formula: copy to clipboard
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] SUMIF formula returning negative value & I need it to be positive
    By dosbirn in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 07-11-2013, 05:10 PM
  2. need one formula for returning positive or negative time w/out #######
    By completelyhis in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 05-11-2013, 09:12 AM
  3. looking up a master sheet and returning positive values only
    By finlandstation in forum Excel General
    Replies: 3
    Last Post: 12-17-2007, 01:09 AM
  4. Returning only positive values from a function
    By Ceves in forum Excel General
    Replies: 1
    Last Post: 04-02-2006, 10:57 PM
  5. returning positive values based on dates
    By scottwilsonx in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-10-2005, 08:37 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1