Computing.Net > Forums > Office Software > How to writ a formula in Excel

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

How to writ a formula in Excel

Reply to Message Icon

Name: alpha
Date: March 29, 2003 at 16:34:16 Pacific
OS: Win xp pro
CPU/Ram: P3-500/256
Comment:

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 ?



Sponsored Link
Ads by Google

Response Number 1
Name: CyberSlug
Date: March 29, 2003 at 23:23:33 Pacific
Reply:

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 Editor

2) In the VBE window, click
Insert / Module

3) 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 Function

4) 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.


0

Response Number 2
Name: alpha
Date: March 30, 2003 at 06:02:29 Pacific
Reply:

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.


0

Response Number 3
Name: CyberSlug
Date: March 30, 2003 at 10:47:57 Pacific
Reply:

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


0

Response Number 4
Name: alpha
Date: March 30, 2003 at 14:41:30 Pacific
Reply:

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.


0

Response Number 5
Name: CyberSlug
Date: March 30, 2003 at 16:47:57 Pacific
Reply:

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.


0

Related Posts

See More



Response Number 6
Name: taxi
Date: April 1, 2003 at 00:05:52 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Office Software Forum Home


Sponsored links

Ads by Google


Results for: How to writ a formula in Excel

Comparing text values in excel and www.computing.net/answers/office/comparing-text-values-in-excel-and-/7824.html

how to make adding form in excel. www.computing.net/answers/office/how-to-make-adding-form-in-excel/334.html

deleting a row in Excel 2000 macro www.computing.net/answers/office/deleting-a-row-in-excel-2000-macro/1875.html