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

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
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 10,593
Default Need help writing a formula

=SUM(IV1:INDEX(1:1,MAX(IF((1:1=0)*(1:1<""),COLUMN (1:1)))))

this is an array formula, so comit with Ctrl-Shift-Enter

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"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



  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 34
Default Need help writing a formula

Thanks Bob for your response. However, your formula doesn't appear to be
working. When I enter it, I get a total of 465 no matter what numbers I
input in to the row of cells. I'm not sure what the "IV1" in your formula
represents. I'm trying to add across the row.
phyllis


"Bob Phillips" wrote:

=SUM(IV1:INDEX(1:1,MAX(IF((1:1=0)*(1:1<""),COLUMN (1:1)))))

this is an array formula, so comit with Ctrl-Shift-Enter

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"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




  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3,268
Default Need help writing a formula

Are you entering values in row 1?


--


Regards,


Peo Sjoblom




"phyllis" wrote in message
...
Thanks Bob for your response. However, your formula doesn't appear to be
working. When I enter it, I get a total of 465 no matter what numbers I
input in to the row of cells. I'm not sure what the "IV1" in your formula
represents. I'm trying to add across the row.
phyllis


"Bob Phillips" wrote:

=SUM(IV1:INDEX(1:1,MAX(IF((1:1=0)*(1:1<""),COLUMN (1:1)))))

this is an array formula, so comit with Ctrl-Shift-Enter

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my
addy)



"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






  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 34
Default Need help writing a formula

Hi, I just realized this error seconds before your post. Acutally the I'm
working in row 4. Do I change all of the 1:1' s in the formula to 4:4?
--
phyllis


"Peo Sjoblom" wrote:

Are you entering values in row 1?


--


Regards,


Peo Sjoblom




"phyllis" wrote in message
...
Thanks Bob for your response. However, your formula doesn't appear to be
working. When I enter it, I get a total of 465 no matter what numbers I
input in to the row of cells. I'm not sure what the "IV1" in your formula
represents. I'm trying to add across the row.
phyllis


"Bob Phillips" wrote:

=SUM(IV1:INDEX(1:1,MAX(IF((1:1=0)*(1:1<""),COLUMN (1:1)))))

this is an array formula, so comit with Ctrl-Shift-Enter

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my
addy)



"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








  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 10,593
Default Need help writing a formula

=SUM(IV4:INDEX(4:4,MAX(IF((4:4=0)*(4:4<""),COLUMN (4:4)))))

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"phyllis" wrote in message
...
Hi, I just realized this error seconds before your post. Acutally the I'm
working in row 4. Do I change all of the 1:1' s in the formula to 4:4?
--
phyllis


"Peo Sjoblom" wrote:

Are you entering values in row 1?


--


Regards,


Peo Sjoblom




"phyllis" wrote in message
...
Thanks Bob for your response. However, your formula doesn't appear to
be
working. When I enter it, I get a total of 465 no matter what numbers
I
input in to the row of cells. I'm not sure what the "IV1" in your
formula
represents. I'm trying to add across the row.
phyllis


"Bob Phillips" wrote:

=SUM(IV1:INDEX(1:1,MAX(IF((1:1=0)*(1:1<""),COLUMN (1:1)))))

this is an array formula, so comit with Ctrl-Shift-Enter

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my
addy)



"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








  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,549
Default Need help writing a formula

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
  #8   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,549
Default Need help writing a formula

Further...
The function will work on any row not just row 1.
Jim Cone

  #9   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 34
Default Need help writing a formula

thanks I again Jim. It works great. I found my problem, was show formulas
was checked in options. thanks again you're the best!
--
phyllis


"Jim Cone" wrote:

Further...
The function will work on any row not just row 1.
Jim Cone


  #10   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 34
Default Need help writing a formula

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



  #11   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 34
Default Need help writing a formula

Hi Jim,

Can you write that code to ignore blank cells in the row? I found that it
only works if there are no blank cells in the row. The numbers in the
columns represents days of the month and the data is enter each day, so there
are blank cells until the end of the month. thanks!
--
phyllis


"phyllis" wrote:

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

  #12   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,549
Default Need help writing a formula

phyllis,
Yes I can, but only because Phyllis was the name of my first girlfriend. <g
See if this does what you want?
'---
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 Len(rng(N)) 0 Then 'new line here
If rng(N) < 0 Then
dblSum = dblSum + rng(N).Value
Else
Exit For
End If
End If 'new line here
Next
AddAfterZero = dblSum
Set rng = Nothing
Exit Function
BadSum:
AddAfterZero = "Error " & Err.Number
End Function
'---
Jim Cone
Portland, Oregon USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)




"phyllis"
wrote in message
Hi Jim,
Can you write that code to ignore blank cells in the row? I found that it
only works if there are no blank cells in the row. The numbers in the
columns represents days of the month and the data is enter each day, so there
are blank cells until the end of the month. thanks!
--
phyllis

  #13   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,549
Default Need help writing a formula

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

  #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


Reply
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 07:11 PM.

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"