+ Reply to Thread
Results 1 to 4 of 4

Sum column that contains both numeric and text values

  1. #1
    Registered User
    Join Date
    01-12-2010
    Location
    Massachusetts
    MS-Off Ver
    Excel 2010
    Posts
    47

    Sum column that contains both numeric and text values

    I am going back over code that I wrote while learning VBA. There is a lot of what I call "brute force" code. The code works. Just extremely verbose. I know there are neater and more efficient ways to accomplish the task.

    Here is an example:

    I want to sum a column of values. The column contains both text and numeric values. I used the following code to accomplish the task:

    Please Login or Register  to view this content.
    The result is that Range("B28") holds the sum of the numeric values B19:B25. Cells B20,22,24 are blank.
    If every cell in the named ranges contains ND - B28 contains ND.


    I have a strong feeling there is a much simpler way to accomplish the task.

    As always - thanks to all for looking and helping.
    Last edited by chromachem; 04-27-2010 at 09:08 AM.

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,902

    Re: Sum column that contains both numeric and text values

    I don't think this is the first time... but why are you marking your threads as Solved prior to being Solved... you will not have luck getting people to help if they think you solved it already.
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Forum Contributor wamp's Avatar
    Join Date
    11-10-2008
    Location
    Norway
    MS-Off Ver
    97, 2000 & 2003 (diff. workstations)
    Posts
    184

    Re: Sum column that contains both numeric and text values

    You could do it like this?
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    01-12-2010
    Location
    Massachusetts
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Sum column that contains both numeric and text values

    The reason I marked the thread as solved is because I realized I had made a mistake. It turns out that I can just sum the range and the text is ignored. I posted the thread and then found the answer moments later.
    Please Login or Register  to view this content.
    It had never occurred to me that the text values in the column were not an issue.

    Thanks to wamp for the code that solves the problem in a loop.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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