+ Reply to Thread
Results 1 to 4 of 4

Sum only positive decimals

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-23-2013
    Location
    Hungary
    MS-Off Ver
    Excel 2013
    Posts
    331

    Sum only positive decimals

    Hello,

    I have some problem when I would like to sum only positive decimals on userform, I would like to separate the numbers with comma (",") and sum them, the format should be "0,0" and only numbers and "," can be given in textboxes. How should I do this?

    Thanks in advance the reply!
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    05-29-2013
    Location
    MD
    MS-Off Ver
    Excel 365
    Posts
    148

    Re: Sum only positive decimals

    Hi Villalobos,

    I assume when you say decimals you mean integers (whole numers) - please correct me if you mean the part of the number after the decimal point.

    This code will sum only the positive integers.

    Private Sub CommandButton1_Click()
        
        Dim t1, t2
        Dim total As Integer
        
        
        t1 = Split(TextBox1.Value, ",")
        t2 = Split(TextBox2.Value, ",")
        
        For x = LBound(t1) To UBound(t1)
            If t1(x) > 0 Then total = total + t1(x)
        Next x
        
        For x = LBound(t2) To UBound(t2)
            If t2(x) > 0 Then total = total + t2(x)
        Next x
        
        TextBox3.Value = total
    End Sub
    Thanks,
    Duncan

  3. #3
    Forum Contributor
    Join Date
    12-23-2013
    Location
    Hungary
    MS-Off Ver
    Excel 2013
    Posts
    331

    Re: Sum only positive decimals

    hi,

    I mean for instance:
    if i entry in textbox1 1,2 and 2,6 in textbox2 then I would like to see in textbox3 3,8.

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Sum only positive decimals


    Hi,

    use CDbl function to convert each textbox value to number to sum them …

    Regards !

+ 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. Replies: 2
    Last Post: 01-07-2014, 04:34 AM
  2. Positive to a Positive and Negative to a Positve
    By alorenzini in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-16-2011, 11:47 AM
  3. Replies: 1
    Last Post: 08-14-2009, 11:17 AM
  4. adding positive and negative numbers all as positive
    By tomvh444 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-18-2009, 04:08 PM
  5. convert negative decimals to positive
    By Spike in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-15-2006, 06:15 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