LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #14   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 34
Default Need help writing a formula

Jim it works perfectly now. Thank you so much.
--
phyllis


"Jim Cone" wrote:

phyllis,
I don't fully understand the problem you have with the function.

The return value of the function is treated as a number for me.
It is right aligned in the cell. I set the cell format before entering the formula.
I tested the function result by using the its cell address in a Sum function with out a problem...
=SUM(X2:Z2)
I also tested it by calling it within a formula...
=SUM(addafterzero(A1:K1), X2, 100) - and no problem.

I am using xl2002 today on Windows XP.
--
Jim Cone
Portland, Oregon USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"phyllis"
wrote in message
Hi Jim,
Thank you so, much. I can tell this is going to work, because whenever I
create the forumla using the function, it show the right total. However,
whenever I try use the =AddAfterZero function, excel wants to treat it like
text instead of a formula, even though I've changed the cell value to
"number". I don't understand it. I'm using MS Office 2003 version of Excel
--
phyllis


"Jim Cone" wrote:
phyllis,
Another way using a custom function...
Copy the code below into a standard module and enter this formula in a cell...

= AddAfterZero(A1:W1)

Works on first row of the specified cells.
Note: you can also select the cells instead of typing them in.
'Code starts----

Function AddAfterZero(ByRef rng As Excel.Range) As Variant
On Error GoTo BadSum
Dim N As Long
Dim dblSum As Double
Set rng = rng.Rows(1).Cells
For N = rng.Count To 1 Step -1
If rng(N) < 0 Then
dblSum = dblSum + rng(N).Value
Else
Exit For
End If
Next
AddAfterZero = dblSum
Set rng = Nothing
Exit Function
BadSum:
AddAfterZero = "Error " & Err.Number
End Function

'Code ends----
Jim Cone
Portland, Oregon USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)




"phyllis"
wrote in message
I need a formula that will add a string of cells until it finds a cell with a
zero, then start the adding again. For example

a b c d e f g h i j k l m n o p q r s t u v
1 8 8 8 0 8 6 5 8 9 0 6 5 4 8 7 6 0 0 5 5 5 5

So the formula would add cells a1 thru v1, but each time it encountered a
zero, ignore the previous cells and start the calucation from the next cell.
So the total for row 1 in this example would be 20, which is the total of
cells s1 thru v1
Any help you can provide is very much appreciated.
thanks
--
phyllis


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with writing a formula Soth Excel Worksheet Functions 1 March 15th 06 03:51 PM
Need Help Writing a Formula Lynn Excel Worksheet Functions 11 September 11th 05 07:51 PM
writing a formula wolfmasterr Excel Discussion (Misc queries) 3 May 23rd 05 02:27 PM
Writing a Formula indansr About this forum 0 May 16th 05 08:51 PM
I need help writing a formula. John III Excel Worksheet Functions 4 December 31st 04 07:26 PM


All times are GMT +1. The time now is 08:13 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"