List of numbers to formula

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • if1467
    New Member
    • Feb 2008
    • 25

    #1

    List of numbers to formula

    I am trying to create a small VB program that will take a list of numbers in excel and put it into a single cell.

    Example:
    Turn this:
    -547119.67
    -19700.00
    -2170.50
    115.00
    10504.56
    186131.59
    -75669.81
    17180.82
    -44261.34

    Into this:

    =-547119.67-19700-2170.50+115+105 04.56+186131.59-75669.81+17180. 82-44261.34

    I need have it so the cells reads out as a single number, not text. Also, I need to do this in VB because I will be surrounding it with other parameters to select which numbers in the list to use.

    Thanks for any Help!!
  • kadghar
    Recognized Expert Top Contributor
    • Apr 2007
    • 1302

    #2
    Originally posted by if1467
    I am trying to create a small VB program that will take a list of numbers in excel and put it into a single cell.

    Thanks for any Help!!
    use FOR - NEXT or DO-LOOP and CELLS... may be WORKSHEETS

    this might give you a general idea:

    [CODE=vb]sub something()
    dim i as long
    dim b as double
    for i = 1 to 10
    b= b + cells(i,1)
    next
    cells(1,2)=b
    end sub[/CODE]

    will sum A1:A10 and write the result in B1

    well
    HTH

    Comment

    • kadghar
      Recognized Expert Top Contributor
      • Apr 2007
      • 1302

      #3
      Oh in case i misunderstood the question

      [CODE=vb]sub something()
      dim i as long
      dim b as string
      b = "="
      for i = 1 to 10
      if mid(cells(i,1), 1,1)="-" then
      b= b & cells(i,1)
      else
      b= b & "+" & cells(i,1)
      end if
      next
      cells(1,2)=b
      end sub[/CODE]

      this might be of help as well

      Comment

      • if1467
        New Member
        • Feb 2008
        • 25

        #4
        Originally posted by kadghar
        use FOR - NEXT or DO-LOOP and CELLS... may be WORKSHEETS

        will sum A1:A10 and write the result in B1

        well
        HTH
        That is a good start, but in addtion to this I need the out put cell to have all the numbers in the formula, not just the sum.

        Any ideas?

        Comment

        • if1467
          New Member
          • Feb 2008
          • 25

          #5
          Originally posted by kadghar
          Oh in case i misunderstood the question

          [CODE=vb]sub something()
          dim i as long
          dim b as string
          b = "="
          for i = 1 to 10
          if mid(cells(i,1), 1,1)="-" then
          b= b & cells(i,1)
          else
          b= b & "+" & cells(i,1)
          end if
          next
          cells(1,2)=b
          end sub[/CODE]

          this might be of help as well
          That's it!!!

          Thanks so much!!!

          Comment

          • kadghar
            Recognized Expert Top Contributor
            • Apr 2007
            • 1302

            #6
            Originally posted by if1467
            That is a good start, but in addtion to this I need the out put cell to have all the numbers in the formula, not just the sum.

            Any ideas?
            yes, sorry, check post #3

            Comment

            Working...