Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 740
Default how to sum this easily...?

hello again gangs,

below is my sample data
A B C
10 0
10 1.00
14 2.00 =(10+14+12+10)=46
12 1.50
10 0.50
16 0
10 0
10 -0.90
8 -1.90
12 -2.00 =(10+8+12+10)=40
10 -1.80
10 0
10 1.00
---------------------------

i need to sum many SEPARATE ranges in column A, if column B <0, and place
the summed range total on column C where the max or min value (other than 0)
on column B is adjacent.
i do not have blank cells ....

really tried this but maybe i can't just do it without this forum...

regards
driller
--
*****
birds of the same feather flock together..

  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 4,339
Default how to sum this easily...?

Hi,
Try this macro:

Sub sumit()

Dim rnga As Range, rngb As Range
Dim r1 As Long, r2 As Long, sr As Long, lastrow As Long, rmax As Long
Dim tot As Double, maxb As Double

lastrow = Cells(Rows.Count, "A").End(xlUp).Row
sr = 0
Do
Do
sr = sr + 1
Loop Until Cells(sr, "B") < 0
r1 = sr
maxb = 0
Do
If Abs(Cells(sr, "B")) Abs(maxb) Then
maxb = Cells(sr, "B")
End If
sr = sr + 1
Loop Until Cells(sr, "B") = 0
r2 = sr - 1
Set rnga = Range(Cells(r1, "A"), Cells(r2, "A"))
Set rngb = Range(Cells(r1, "B"), Cells(r2, "B"))
tot = Application.Sum(rnga)
rmax = Application.Match(maxb, rngb, 0) + r1 - 1
Cells(rmax, "C") = tot

Loop Until sr = lastrow

End Sub

HTH

"driller" wrote:

hello again gangs,

below is my sample data
A B C
10 0
10 1.00
14 2.00 =(10+14+12+10)=46
12 1.50
10 0.50
16 0
10 0
10 -0.90
8 -1.90
12 -2.00 =(10+8+12+10)=40
10 -1.80
10 0
10 1.00
---------------------------

i need to sum many SEPARATE ranges in column A, if column B <0, and place
the summed range total on column C where the max or min value (other than 0)
on column B is adjacent.
i do not have blank cells ....

really tried this but maybe i can't just do it without this forum...

regards
driller
--
*****
birds of the same feather flock together..

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 740
Default how to sum this easily...?

Hi Toppers,
thanks for your concerned reply, i never thought that summing it easily
needs a macro,,,
i did tested it and it do serve the purpose in the first case,,,i dont want
to change anything in this macro so if you could please adjust it with
something like this...

the data on col.B [-/0/+] are updated everytime for surveying works....
so when i try to replace values on the zero's (0) and run the macro
Again---then the result of the first macro-run are not re-updated....can u
make your macro to clear previous results on col.B when a second or third
re-run of macro...

thanks a lot..and more power
regards
--
*****
birds of the same feather flock together..



"Toppers" wrote:

Hi,
Try this macro:

Sub sumit()

Dim rnga As Range, rngb As Range
Dim r1 As Long, r2 As Long, sr As Long, lastrow As Long, rmax As Long
Dim tot As Double, maxb As Double

lastrow = Cells(Rows.Count, "A").End(xlUp).Row
sr = 0
Do
Do
sr = sr + 1
Loop Until Cells(sr, "B") < 0
r1 = sr
maxb = 0
Do
If Abs(Cells(sr, "B")) Abs(maxb) Then
maxb = Cells(sr, "B")
End If
sr = sr + 1
Loop Until Cells(sr, "B") = 0
r2 = sr - 1
Set rnga = Range(Cells(r1, "A"), Cells(r2, "A"))
Set rngb = Range(Cells(r1, "B"), Cells(r2, "B"))
tot = Application.Sum(rnga)
rmax = Application.Match(maxb, rngb, 0) + r1 - 1
Cells(rmax, "C") = tot

Loop Until sr = lastrow

End Sub

HTH

"driller" wrote:

hello again gangs,

below is my sample data
A B C
10 0
10 1.00
14 2.00 =(10+14+12+10)=46
12 1.50
10 0.50
16 0
10 0
10 -0.90
8 -1.90
12 -2.00 =(10+8+12+10)=40
10 -1.80
10 0
10 1.00
---------------------------

i need to sum many SEPARATE ranges in column A, if column B <0, and place
the summed range total on column C where the max or min value (other than 0)
on column B is adjacent.
i do not have blank cells ....

really tried this but maybe i can't just do it without this forum...

regards
driller
--
*****
birds of the same feather flock together..

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 4,339
Default how to sum this easily...?

I am asuming you want the results in column C cleared (not column B!):

Sub sumit()

Dim rnga As Range, rngb As Range
Dim r1 As Long, r2 As Long, sr As Long, lastrow As Long, rmax As Long
Dim tot As Double, maxb As Double

Columns(3).ClearContents ' Clear column C

lastrow = Cells(Rows.Count, "A").End(xlUp).Row
sr = 0
Do
Do
sr = sr + 1
Loop Until Cells(sr, "B") < 0
r1 = sr
maxb = 0
Do
If Abs(Cells(sr, "B")) Abs(maxb) Then
maxb = Cells(sr, "B")
End If
sr = sr + 1
Loop Until Cells(sr, "B") = 0
r2 = sr - 1
Set rnga = Range(Cells(r1, "A"), Cells(r2, "A"))
Set rngb = Range(Cells(r1, "B"), Cells(r2, "B"))
tot = Application.Sum(rnga)
rmax = Application.Match(maxb, rngb, 0) + r1 - 1
Cells(rmax, "C") = tot

Loop Until sr = lastrow

End Sub

"driller" wrote:

Hi Toppers,
thanks for your concerned reply, i never thought that summing it easily
needs a macro,,,
i did tested it and it do serve the purpose in the first case,,,i dont want
to change anything in this macro so if you could please adjust it with
something like this...

the data on col.B [-/0/+] are updated everytime for surveying works....
so when i try to replace values on the zero's (0) and run the macro
Again---then the result of the first macro-run are not re-updated....can u
make your macro to clear previous results on col.B when a second or third
re-run of macro...

thanks a lot..and more power
regards
--
*****
birds of the same feather flock together..



"Toppers" wrote:

Hi,
Try this macro:

Sub sumit()

Dim rnga As Range, rngb As Range
Dim r1 As Long, r2 As Long, sr As Long, lastrow As Long, rmax As Long
Dim tot As Double, maxb As Double

lastrow = Cells(Rows.Count, "A").End(xlUp).Row
sr = 0
Do
Do
sr = sr + 1
Loop Until Cells(sr, "B") < 0
r1 = sr
maxb = 0
Do
If Abs(Cells(sr, "B")) Abs(maxb) Then
maxb = Cells(sr, "B")
End If
sr = sr + 1
Loop Until Cells(sr, "B") = 0
r2 = sr - 1
Set rnga = Range(Cells(r1, "A"), Cells(r2, "A"))
Set rngb = Range(Cells(r1, "B"), Cells(r2, "B"))
tot = Application.Sum(rnga)
rmax = Application.Match(maxb, rngb, 0) + r1 - 1
Cells(rmax, "C") = tot

Loop Until sr = lastrow

End Sub

HTH

"driller" wrote:

hello again gangs,

below is my sample data
A B C
10 0
10 1.00
14 2.00 =(10+14+12+10)=46
12 1.50
10 0.50
16 0
10 0
10 -0.90
8 -1.90
12 -2.00 =(10+8+12+10)=40
10 -1.80
10 0
10 1.00
---------------------------

i need to sum many SEPARATE ranges in column A, if column B <0, and place
the summed range total on column C where the max or min value (other than 0)
on column B is adjacent.
i do not have blank cells ....

really tried this but maybe i can't just do it without this forum...

regards
driller
--
*****
birds of the same feather flock together..

  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 740
Default how to sum this easily...?

Toppers,

thanks it work

i'll close this post now and will extend my inquiry on the next post "paging
Toppers" in a few minutes...

regards and more power...
--
*****
birds of the same feather flock together..



"Toppers" wrote:

I am asuming you want the results in column C cleared (not column B!):

Sub sumit()

Dim rnga As Range, rngb As Range
Dim r1 As Long, r2 As Long, sr As Long, lastrow As Long, rmax As Long
Dim tot As Double, maxb As Double

Columns(3).ClearContents ' Clear column C

lastrow = Cells(Rows.Count, "A").End(xlUp).Row
sr = 0
Do
Do
sr = sr + 1
Loop Until Cells(sr, "B") < 0
r1 = sr
maxb = 0
Do
If Abs(Cells(sr, "B")) Abs(maxb) Then
maxb = Cells(sr, "B")
End If
sr = sr + 1
Loop Until Cells(sr, "B") = 0
r2 = sr - 1
Set rnga = Range(Cells(r1, "A"), Cells(r2, "A"))
Set rngb = Range(Cells(r1, "B"), Cells(r2, "B"))
tot = Application.Sum(rnga)
rmax = Application.Match(maxb, rngb, 0) + r1 - 1
Cells(rmax, "C") = tot

Loop Until sr = lastrow

End Sub

"driller" wrote:

Hi Toppers,
thanks for your concerned reply, i never thought that summing it easily
needs a macro,,,
i did tested it and it do serve the purpose in the first case,,,i dont want
to change anything in this macro so if you could please adjust it with
something like this...

the data on col.B [-/0/+] are updated everytime for surveying works....
so when i try to replace values on the zero's (0) and run the macro
Again---then the result of the first macro-run are not re-updated....can u
make your macro to clear previous results on col.B when a second or third
re-run of macro...

thanks a lot..and more power
regards
--
*****
birds of the same feather flock together..



"Toppers" wrote:

Hi,
Try this macro:

Sub sumit()

Dim rnga As Range, rngb As Range
Dim r1 As Long, r2 As Long, sr As Long, lastrow As Long, rmax As Long
Dim tot As Double, maxb As Double

lastrow = Cells(Rows.Count, "A").End(xlUp).Row
sr = 0
Do
Do
sr = sr + 1
Loop Until Cells(sr, "B") < 0
r1 = sr
maxb = 0
Do
If Abs(Cells(sr, "B")) Abs(maxb) Then
maxb = Cells(sr, "B")
End If
sr = sr + 1
Loop Until Cells(sr, "B") = 0
r2 = sr - 1
Set rnga = Range(Cells(r1, "A"), Cells(r2, "A"))
Set rngb = Range(Cells(r1, "B"), Cells(r2, "B"))
tot = Application.Sum(rnga)
rmax = Application.Match(maxb, rngb, 0) + r1 - 1
Cells(rmax, "C") = tot

Loop Until sr = lastrow

End Sub

HTH

"driller" wrote:

hello again gangs,

below is my sample data
A B C
10 0
10 1.00
14 2.00 =(10+14+12+10)=46
12 1.50
10 0.50
16 0
10 0
10 -0.90
8 -1.90
12 -2.00 =(10+8+12+10)=40
10 -1.80
10 0
10 1.00
---------------------------

i need to sum many SEPARATE ranges in column A, if column B <0, and place
the summed range total on column C where the max or min value (other than 0)
on column B is adjacent.
i do not have blank cells ....

really tried this but maybe i can't just do it without this forum...

regards
driller
--
*****
birds of the same feather flock together..

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
How do I easily link a block of cells in one spreadsheet to anothe eudorajane Excel Discussion (Misc queries) 3 September 19th 06 06:05 AM
Lock easily breaks. kyoshirou Excel Discussion (Misc queries) 3 September 18th 06 06:17 AM
how to copy the same cell across different work books into another workbook easily? sageerai Excel Discussion (Misc queries) 2 November 11th 05 09:46 PM
How to easily collapse columns? Grd Excel Discussion (Misc queries) 3 September 2nd 05 08:02 PM
How do I easily draw in Excel the Upper and Lower limits of a con. Judy Charts and Charting in Excel 3 January 12th 05 09:21 AM


All times are GMT +1. The time now is 06:17 PM.

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

About Us

"It's about Microsoft Excel"