VbA question ( function)

  • Thread starter rose_55
  • Start date
  • #1
rose_55
1
0
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 )
Next
myfunction= sum
End Function
 
Last edited:

Answers and Replies

  • #2
Integral
Staff Emeritus
Science Advisor
Gold Member
7,253
63
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
 

Suggested for: VbA question ( function)

  • Last Post
2
Replies
63
Views
2K
  • Last Post
Replies
16
Views
796
Replies
2
Views
412
Replies
3
Views
712
  • Last Post
Replies
18
Views
561
Replies
26
Views
2K
Replies
5
Views
523
Replies
5
Views
809
Replies
6
Views
424
Top