+ Reply to Thread
Results 1 to 7 of 7

Adding values as a total instead of just creating a big nonsense figure.

  1. #1
    Registered User
    Join Date
    10-08-2009
    Location
    Hull, England
    MS-Off Ver
    Excel 2003, Excel 2007
    Posts
    73

    Adding values as a total instead of just creating a big nonsense figure.

    I have a spreadsheet which im just setting up as a test for now, i have a row of data and in cell G1 for instance i have a number.
    When the user inputs a new number in a Textbox i want it to add that number to the existing number in G1 here is the code for this.

    Private Sub CommandButton1_Click()
    Sheets("Sheet1").Range("G1").Value = Sheets("Sheet1").Range("G1").Value & TextBox1.Value
    End Sub


    The above code, just adds the numbers together to make a bigger number like for example:

    G1 = 1 & Textbox1 = 1, when i press the command button the value in cell G1 = 11, instead of it being the number 2 which is 1 + 1.
    Can this be changed?

  2. #2
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,447

    Re: Adding values as a total instead of just creating a big nonsense figure.

    Hi
    perhaps first add some code tags as per forum rules

  3. #3
    Registered User
    Join Date
    10-08-2009
    Location
    Hull, England
    MS-Off Ver
    Excel 2003, Excel 2007
    Posts
    73

    Re: Adding values as a total instead of just creating a big nonsense figure.

    I have a spreadsheet which im just setting up as a test for now, i have a row of data and in cell G1 for instance i have a number.
    When the user inputs a new number in a Textbox i want it to add that number to the existing number in G1 here is the code for this.

    Please Login or Register  to view this content.
    The above code, just adds the numbers together to make a bigger number like for example:

    G1 = 1 & Textbox1 = 1, when i press the command button the value in cell G1 = 11, instead of it being the number 2 which is 1 + 1.
    Can this be changed?

  4. #4
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: Adding values as a total instead of just creating a big nonsense figure.

    I'm not a VBA man myself but the ampersand & is usually used for concatenation. Maybe the problem is there?

  5. #5
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Adding values as a total instead of just creating a big nonsense figure.

    Like this, maybe:

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    10-08-2009
    Location
    Hull, England
    MS-Off Ver
    Excel 2003, Excel 2007
    Posts
    73

    Re: Adding values as a total instead of just creating a big nonsense figure.

    Spot on that man, i knew the ampersand wasn't doing much when i tried the plus i got a runtime error, i never implemented the Val() so thank you.
    Thread Resolved.

  7. #7
    Valued Forum Contributor
    Join Date
    08-29-2011
    Location
    Mississauga, CANADA
    MS-Off Ver
    Excel 2010
    Posts
    503

    Re: Adding values as a total instead of just creating a big nonsense figure.

    Use:
    Please Login or Register  to view this content.
    Regards,
    Khaled Elshaer
    www.BIMcentre.com

    Remember To Do the Following....
    1. Thank those who have helped you by clicking the Star below their post.
    2. Mark your post SOLVED if it has been answered satisfactorily:
    • Select Thread Tools (on top of your 1st post)
    • Select Mark this thread as Solved

+ 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