Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I have a question about write a simple format in Excel of Office 2000.
I want adding every nine line number togather ( example = c5+c14+c23+c32 ... until to +c275 )
Is there any simple formula I can writer for it ?

You can write a formula (called "mySum" in my example) with Visual Basic in Excel:
1) Open the VBE by clicking
Tools / Macros / Visual Basic Editor2) In the VBE window, click
Insert / Module3) Paste the following text into there:
Function mySum(firstCell As Range, interval As Integer, lastCell As Range)
temp = 0
For i = firstCell.Row To lastCell.Row Step interval
temp = temp + firstCell.Cells(i).Value
Next i
mySum = temp
End Function4) Close the VBE window to get back to Excel
5) Finally use the formula "mySum" where you need it
With your example, you would say:
=mySum(C5, 9, C275)
I hope you can figure this out and adapt it to your needs.

Dear CyberSlug:
Thank you for help.
I following your instruction -- paste text into module of VBE. At excel, I type "=mySum(c5,9,c275) into finally total line.
But it did not working, it did not adding any number, finally total alway is 0.
Would you help me to fix this problem.
Thank you.

You're right! I had the Visual Basic code wrong. The line with "temp = temp + ..." should be replaced with:
temp = temp + Cells(i, firstCell.Column)
This *should* work now

Dear CyberSlug,
I copy the formular into VBE, my next question is how to run the Module? Right now, the Sum won't update by itself, I have to go to the formula and insert a space, then it will give me a new sum. Should I Copy it to macro and use a shortcut key to run it?
Thank you.

Hmm... it only updates if you change the value of the first or last cell.
I don't know what to do. Maybe post a new message about "Result of Excel VB formula does not auto-update"
Perhaps someone in the programming forum would know a solution.

i've got it .
Insert a column, and put in the first top cell "1" . Next from the second line to the end, a formula =l(-1)c + 1 . It'll give u a line number increasing . In the column u want to have ur sum, u make a formula = if ("function that makes rest of division"*( line number; 8)>0;"";sum(l(-8)c(-1):lc(-1)) . *In french the function calls "mod", don't know in ur language...I'm french .If ur lost give ur mail, i'll send u a sample

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |