Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / March 2006

Tip: Looking for answers? Try searching our database.

Sum Multiple Ranges

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
FIRSTROUNDKO - 21 Mar 2006 11:42 GMT
HI,

I have a 1 collumn  which I have seperated in to ranges, of various lengths,
with 4 empty cells below each range I am trying to loop through and sum each
range on the 3rd cell below each range.

Thanks in Advance

Darren
Martin - 21 Mar 2006 13:00 GMT
Here's one way (you have to select the whole column, excluding any headings
and down to the third cell below the final number group):

Sub mySum()
   Dim myCounter As Long
   Dim myTotal As Double
   myTotal = 0
   myCounter = 0
   Do While myCounter <= Selection.Rows.Count
       If ActiveCell.Offset(myCounter, 0).Value <> "" Then
           myTotal = myTotal + ActiveCell.Offset(myCounter, 0).Value
       Else
           ActiveCell.Offset(myCounter + 2, 0).Value = myTotal
           myTotal = 0
           myCounter = myCounter + 3
       End If
       myCounter = myCounter + 1
   Loop
End Sub

> HI,
>
[quoted text clipped - 5 lines]
>
> Darren
Mike Fogleman - 21 Mar 2006 13:07 GMT
Name your ranges rng1, rng 2 rng3, etc then use the following code:

Sub SumRngs()
Dim RngRows As Long
Dim c As String
Dim rngsum As Range
Dim cntr As Long

For cntr = 1 To 3
RngRows = Range("rng" & cntr).Rows.Count
c = Range("rng" & cntr).Address
Range(c).Range("A1").Offset(RngRows + 2, 0).Value =
WorksheetFunction.Sum(Range("rng" & cntr))
Next cntr
End Sub

MIke F

> HI,
>
[quoted text clipped - 7 lines]
>
> Darren
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.