How do you add 2 numbers together in VB from a worksheet?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anoble1
    New Member
    • Jul 2008
    • 246

    How do you add 2 numbers together in VB from a worksheet?

    Hi,

    I have an excel sheet that has a graph in it. The graph is a line graph and has bars that contain 2 numbers that add together that create 1 bar. I have made a textbox that has "Active X" functions on it. meaning that the textbox pulls from VB code. Anyone know of the code to grab numbers from a worksheet and add them together?

    EX:
    Code:
    Private Sub TextBox1_Change()
    Sheets("Sheet1").Select
    Range("F4:G4").Select
    textbox = F4.value+G4.value
    End Sub
    Maybe something like that but that will not work.

    i am just trying to populate a textbox with VB by adding 2 numbers from a worksheet.
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    There are several ways to accomplish this, namely:
    1. Directly assign Result to Textbox on Form:
      Code:
      TextBox1 = Cells(4, 6) + Cells(4, 7)
      TextBox2 = Range("F4") + Range("G4")
    2. Apply Formula to Cell:
      Code:
      =SUM(F4:G4)

    Comment

    • Rabbit
      Recognized Expert MVP
      • Jan 2007
      • 12517

      #3
      This thread has been moved to the new Excel forum.

      Comment

      Working...