+ Reply to Thread
Results 1 to 16 of 16

Summing numeric values in a row that contains both numbers and dates

  1. #1
    Registered User
    Join Date
    07-21-2014
    Location
    Wilmington, North Carolina
    MS-Off Ver
    2010
    Posts
    4

    Summing numeric values in a row that contains both numbers and dates

    I have a row of values that contains dates and numeric values. I want to SUM all of the numeric values within this row but am having problems figuring out how to do this.

    I have tried several array formulas, such as {=SUMIF(K17:CC17,isnum(K17:CC17),K17:CC17)} where "isnum" is a VBA function that uses IsNumeric to determine if a cell contains a numeric value (will, according to Excel Help, return FALSE if the cell contains a date value).

    I have tried using the built-in function ISNUMBER but that seems to return TRUE when the cell contains a date, so that's of no help.

    I am using Excel 2010.

    Thanks.

    Function isnum(rng As Range) As Boolean
    isnum = IsNumeric(rng)
    End Function

  2. #2
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Summing numeric values in a row that contains both numbers and dates

    Hi pbeaven and welcome to the forum,

    I suggest you upload a sample spreadsheet with about 10-15 rows of data so we could figure our a solution for you.

    To upload a file click on Go Advanced at the bottom of your screen then click on PaperClip icon and Add Files, Select File, locate your file and click Open then click Upload and click Done
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Summing numeric values in a row that contains both numbers and dates

    Hi,

    Dates are of course numbers so as you've found you can't use ISNUMBER.

    Are the numbers you want to sum within a particular range of values. Or putting it another way is there any other way of distinguishing your date numbers from the numbers to sum? Perhaps one of the adjacent columns has some other identifier, in which case a SUMIFS() might work. You'll need to upload the workbook and comment on the above if you need more specific help.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    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,939

    Re: Summing numeric values in a row that contains both numbers and dates

    You need to understand this about dates...a date is just a number indicating how many days have passed since 1/1/1900, so today 7/11/14 is actually 41831. excel formats it into something that we recognise as a date

    If you have headings that would ID the columns with dates, you can use that in a SUMIF()
    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

  5. #5
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Summing numeric values in a row that contains both numbers and dates

    Please take a look at this example

    A
    B
    C
    1
    10
    G =CELL("format",A1)
    2
    15
    G
    3
    1/10/2014
    D4
    4
    5/13/2013
    D4
    5
    20
    G
    6
    15
    G
    7
    8
    60
    =SUMIF(B1:B6,"<>D4",A1:A6)

  6. #6
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: Summing numeric values in a row that contains both numbers and dates

    You may also try this to see if this works as per your requirement.

    Please Login or Register  to view this content.
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

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

    Re: Summing numeric values in a row that contains both numbers and dates

    Quote Originally Posted by pbeaven View Post

    I have tried several array formulas, such as {=SUMIF(K17:CC17,isnum(K17:CC17),K17:CC17)}
    The SUMIF function only works on "straight comparisons".

    For example:

    =SUMIF(K17:CC17,">0",K17:CC17) Or: =SUMIF(K17:CC17,">0")

    You can't "manipulate" a range as you have tried with the isnum.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  8. #8
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Summing numeric values in a row that contains both numbers and dates

    Quote Originally Posted by AlKey View Post
    Please take a look at this example
    Nice one. A neat use of the Cell() function.

    Just one small improvement since D4 will only pick up dates formatted as dd/mm/yyyy (or perhaps mm/dd/yyyy if you're one of our country cousins on the other side of the pond ) and not dates formatted as say dd-mmm, then

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

  9. #9
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Summing numeric values in a row that contains both numbers and dates

    Thank you Richard for catching it. I know I shohld've mentioned that.

  10. #10
    Registered User
    Join Date
    07-21-2014
    Location
    Wilmington, North Carolina
    MS-Off Ver
    2010
    Posts
    4

    Re: Summing numeric values in a row that contains both numbers and dates

    Ok, I am attaching a sample spreadsheet and here's what it looks like (I hope):

    SampleBook.jpg

    One of the problems with using the Cell function is that the "format" value that's returned may vary if the user has changed the format, as someone here pointed out. For example, a numeric cell that includes 2 decimals might return "F2" but if you've selected to have a comma delineate thousands, it will return ",2". That's why the VBA function IsNumeric seems so useful.

    As you'll see, each row contains alternating values: a date, then a numeric value, a date, a numeric value, and so on. And you'll see that not all of the cells have values, some will remain blank. I want to be able to sum each row, adding together any numeric values, obviously bypassing any dates. Some of the proposed solutions would work if the values were in a column, but that's not the case.

    Hope this helps.
    Attached Files Attached Files

  11. #11
    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,939

    Re: Summing numeric values in a row that contains both numbers and dates

    Do those columns have headings?

  12. #12
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Summing numeric values in a row that contains both numbers and dates

    Hi,

    If the numbers to sum are always less than 41640 (Jan 1 2014) then

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


    or if the dates and values always alternate then

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



    But I have to ask the obvious question, why are you choosing to record your data in this way and not a more 'normal' layout?

  13. #13
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: Summing numeric values in a row that contains both numbers and dates

    Try this......
    Refer to your attached sheet in post#10
    In O1
    Please Login or Register  to view this content.
    and copy down.
    Attached Files Attached Files

  14. #14
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: Summing numeric values in a row that contains both numbers and dates

    Or more correctly, assuming that all your dates are after the year 2000, you may try this.....

    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    07-21-2014
    Location
    Wilmington, North Carolina
    MS-Off Ver
    2010
    Posts
    4

    Re: Summing numeric values in a row that contains both numbers and dates

    Thanks, stkneer. Your solution does work. It is a workaround but since it does what I need, I'll take it!

    Richard, I'm not sure what a more "normal" layout would be. We have a variable number of "transactions" (payment amount and date) and they are not consistent in terms of frequency nor chronology. The data is more appropriately thought of as a master/child/grandchild relationship, easily handled with a database system where you can support multiple layers of one-to-many record relationships. It's really not a suitable application for a spreadsheet without a lot of rigamarole, witnessed by the fact that in order to get sktneer's solution to work, we need to "fool" the system. I am surprised that a function can't be used in an array formula - or so it seems. Or my IsNum function would have worked???

  16. #16
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Summing numeric values in a row that contains both numbers and dates

    Here is a possibility. The date serial numbers are quite large (Oct 3 1954 is 20,000) and unless the currency amounts are in large amounts one can use this:

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


    If none of the dates is prior to 2010, the 20,000 can be raised to 40,000.
    <---------If you like someone's answer, click the star to the left of one of their posts to give them a reputation point for that answer.
    Ron W

+ 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] Dates Changed to Numeric values
    By drdr01 in forum Excel General
    Replies: 3
    Last Post: 11-14-2012, 07:13 AM
  2. Replies: 1
    Last Post: 11-03-2011, 11:43 AM
  3. Summing range of numbers according to variable dates
    By budapesh in forum Excel General
    Replies: 1
    Last Post: 05-26-2011, 05:46 PM
  4. Summing numeric parts of alphanumeric values
    By amdk8800 in forum Excel General
    Replies: 10
    Last Post: 11-17-2009, 08:27 PM
  5. summing numbers within certain dates
    By anna57 in forum Excel General
    Replies: 1
    Last Post: 11-10-2009, 09:58 AM

Tags for this Thread

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