Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

VbA question ( function)

  1. May 14, 2008 #1
    help pleaase . here is the problem :If a number in a cell is 10, then the total should be 55 which is: 1+2+3+4+5+6+7+8+9+10 , how do i write a module-level( function) like that .this is what i have so far:
    Public Function myfunction()
    Dim sum As Double
    Dim i As Integer
    For i = 1 To 1000 Step 1
    sum = sum + cells(i,1)....( THIS IS THE PART THAT I'M STUCK , I'M NOT GOOD AT MATH )
    myfunction= sum
    End Function
    Last edited: May 14, 2008
  2. jcsd
  3. May 15, 2008 #2


    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Your function sums up the contents of the first column for 1000 rows. You need the upper limit of your loop to be determined by the cell which contains 10.

    For i = 1 to Cells( row, column of cell where 10 lives)

    sum = sum+i

    next i
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?

Similar Discussions: VbA question ( function)
  1. VBA help (Replies: 2)