+ Reply to Thread
Results 1 to 12 of 12

Ignore Text in a Cell and Sum Only the Values of the First 3 Non Zero Numbers

  1. #1
    Registered User
    Join Date
    02-21-2012
    Location
    Vancouver, BC
    MS-Off Ver
    Excel 2007
    Posts
    6

    Ignore Text in a Cell and Sum Only the Values of the First 3 Non Zero Numbers

    Hi there,

    I was able to find an array formula from the forum that could sum the first 3 non zero values in a column.

    =SUM(A1:INDEX(A1:A10,SMALL(IF(A1:A10<>0,ROW(A1:A10)-ROW(A1)+1),3)))

    My problem is that sometimes there would be a cell where it would include text and a value ("d9" for example). When this happens, the array will only sum up the numbers up until the cell with the text and value but not include the value.

    I was looking for a way to modify this array to sum the first 3 non zero numbers ignoring any text and only using the numbers.

    I have attached an example workbook.

    Thanks in advance for your help!
    Attached Files Attached Files

  2. #2
    Forum Expert Tsjallie's Avatar
    Join Date
    09-15-2012
    Location
    NL
    MS-Off Ver
    2010, 2013, 2016
    Posts
    2,077

    Re: Ignore Text in a Cell and Sum Only the Values of the First 3 Non Zero Numbers

    I assume that you want the total of column D to be 4+7+9=20?
    Is there some kind of system in the text/number combinations. E.g. always the same number of text characters or always a number in a certain range (e.g. 0-9).
    If not then a small macro will be necessary. Would that be a problem for you?
    Cheers!
    Tsjallie




    --------
    If your problem is solved, pls mark the thread SOLVED (see Thread Tools in the menu above). Thank you!

    If you think design is an expensive waste of time, try doing without ...

  3. #3
    Forum Expert Tsjallie's Avatar
    Join Date
    09-15-2012
    Location
    NL
    MS-Off Ver
    2010, 2013, 2016
    Posts
    2,077

    Re: Ignore Text in a Cell and Sum Only the Values of the First 3 Non Zero Numbers

    I don't think it can be done with a formula.
    This function which you can use in a formula counts the first n non-zero cells in a range.
    Usage is
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    First parameter is the range and the second is the number of non-zero cells to count (to make it flexible)

    Add this function to a module in your workbook
    Please Login or Register  to view this content.
    It's also added to the attached workbook.
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    02-21-2012
    Location
    Vancouver, BC
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Ignore Text in a Cell and Sum Only the Values of the First 3 Non Zero Numbers

    Hi Tsjallie,

    Thank you for responding to my question. Yes I did wanted the total of the column to be 4+7+9=20.

    Right now the text will always be "d" and then a number.

    I have tested the module and it worked perfectly! Thank you very much!

  5. #5
    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,023

    Re: Ignore Text in a Cell and Sum Only the Values of the First 3 Non Zero Numbers

    Two non-VBA solutions.


    With th No. of cells to be counted in E2 (can be hard-coded)

    1. With a helper column, in B2, copied down:
    =COUNT(A$2:A2)

    In F2, copied, down:
    =SUM($A2:INDEX($A2:$A12,MATCH(E2,$B2:$B12)))

    2. More complex, but no helper, an array formula, copied down:
    =SUM(OFFSET($A2,0,0,SMALL(ISNUMBER($A2:$A12)*ROW($A2:$A12)-ROW($A2)+1,ROWS($A2:$A12)-COUNT($A2:$A12)+MIN(E2,COUNT($A2:$A12)))))

    Array Formulae are a little different from ordinary formulae in that they MUST be confirmed in the FIRST CELL ONLY by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. After that, the array can be dragged down as normal, to cover the desired range.

    You will know the array is active when you see curly brackets { } - or "curly braces" for those of you in the USA, or "flower brackets" for those of you in India - appear around the outside of your formula. If you do not use CTRL+SHIFT+ENTER you will (almost always) get an error message or an incorrect answer. Press F2 on that cell and try again.

    Don't type the curly brackets yourself - it won't work...
    Attached Files Attached Files
    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

  6. #6
    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,023

    Re: Ignore Text in a Cell and Sum Only the Values of the First 3 Non Zero Numbers

    Ignore the above. I completely misread the request

  7. #7
    Registered User
    Join Date
    02-21-2012
    Location
    Vancouver, BC
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Ignore Text in a Cell and Sum Only the Values of the First 3 Non Zero Numbers

    Hi Glenn,

    Thank you for your response. The array formula works for ignoring any cell with text but if the cell includes both text and a number, the array will skip the cell. Is there a way to treat the cell with text and a number as if it was just a number?

    EDIT: I just saw your response. Thank you for your time.

  8. #8
    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,023

    Re: Ignore Text in a Cell and Sum Only the Values of the First 3 Non Zero Numbers

    It doesn't ignore zeros was the main problem. Text/numbers add another level of complexity: well beyond me!! Go with VBA offered earlier.

  9. #9
    Registered User
    Join Date
    02-21-2012
    Location
    Vancouver, BC
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Ignore Text in a Cell and Sum Only the Values of the First 3 Non Zero Numbers

    Quote Originally Posted by Tsjallie View Post
    I don't think it can be done with a formula.
    This function which you can use in a formula counts the first n non-zero cells in a range.
    Usage is
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    First parameter is the range and the second is the number of non-zero cells to count (to make it flexible)

    Add this function to a module in your workbook
    Please Login or Register  to view this content.
    It's also added to the attached workbook.
    Hi Tsjallie,

    It seems that with the code, the number beside the first "d" in the column will be designated as the value of d so it will replace every "d" in the rest of the column as the value beside the first "d". In the akurei.xlsm file, I change the 7 in individual 3 to d7, and the sum changed to 7120 which is 4+7+(7109). Is there a way to correct this?

  10. #10
    Forum Expert Tsjallie's Avatar
    Join Date
    09-15-2012
    Location
    NL
    MS-Off Ver
    2010, 2013, 2016
    Posts
    2,077

    Re: Ignore Text in a Cell and Sum Only the Values of the First 3 Non Zero Numbers

    Oops! Beginner error
    The variable (x) used to collect the numeric part of the cell was initialized at the start of the procedure, but should be initialized for each cell.
    Change is marked red.
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    02-21-2012
    Location
    Vancouver, BC
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Ignore Text in a Cell and Sum Only the Values of the First 3 Non Zero Numbers

    Thanks Tsjallie,

    The code is working as intended now. Cheers!

  12. #12
    Forum Expert Tsjallie's Avatar
    Join Date
    09-15-2012
    Location
    NL
    MS-Off Ver
    2010, 2013, 2016
    Posts
    2,077

    Re: Ignore Text in a Cell and Sum Only the Values of the First 3 Non Zero Numbers

    Good to here that.
    If that solved your problem pls mark the thread SOLVED (see Thread Tools in the menu above).
    Thx for the rep

+ 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. I want a formula to ignore text values in cell references
    By Russellrupert in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 06-05-2016, 03:53 PM
  2. Replies: 4
    Last Post: 07-21-2014, 10:33 AM
  3. Just take the text and ignore the numbers
    By inayat in forum Excel General
    Replies: 5
    Last Post: 09-05-2011, 08:52 AM
  4. Replies: 22
    Last Post: 05-03-2009, 07:29 PM
  5. compare cell values numbers from text
    By rtames in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 01-26-2009, 07:44 AM
  6. [SOLVED] Can I ignore numbers and sort only text in an Excel column?
    By justaMom in forum Excel General
    Replies: 5
    Last Post: 04-26-2006, 09:10 PM
  7. add numbers but ignore text
    By 1vagrowr in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 11-21-2005, 01:00 PM

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