Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 143
Default Sum variable ranges

Two part question:
I have a spreadsheet where I want to sum one of a few ranges.

E15 will contain the sum of E7:E14. Then E30 will contain the sum of
E17:E29 and so on. This is part of a loop function where the code loops
through the sheet and when it hits "Progam Total", it assignes the the
formula in question.

Here is the current code:

Sub Totals()
Dim Client As Range
Dim Spend As Range
Dim Sales As Range

Set Client = Sheet1.Range("C7")
Set Spend = Sheet1.Range("E7")
Set Sales = Sheet1.Range("F7")

Do Until ActiveCell = "STOP"
If Client = "Program Total" Then
Spend = FORMULA TO ADD THE VARIABLE RANGE
Sales = FORMULA TO ADD THE VARIABLE RANGE
Client = Client.Offset(1, 0).Select
Spend = Spend.Offset(1, 0).Select
Sales = Sales.Offset(1, 0).Select
Else
Client = Client.Offset(1, 0).Select
Spend = Spend.Offset(1, 0).Select
Sales = Sales.Offset(1, 0).Select
End If

End Sub

Second Question:
Is there a better way to do this? My experience is that there always is...

Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Sum variable ranges

I assume your loop is closed in your actual code. It is not in your posting.

I don't know that there is a better way, but there is a different way. You
could use a For ... Next loop. You could possibly use a case statement
instead of the If ...Then statement.

My philosophy is that if the code works it is good enough. But I do not
sell my services, so I can afford to be satisfied with that philosophy. A
professional would not be.

Your first question was not very clear about summing one of a few ranges.
You need to clarify that requirement, like which range you want to sum out of
which few.

"PJFry" wrote:

Two part question:
I have a spreadsheet where I want to sum one of a few ranges.

E15 will contain the sum of E7:E14. Then E30 will contain the sum of
E17:E29 and so on. This is part of a loop function where the code loops
through the sheet and when it hits "Progam Total", it assignes the the
formula in question.

Here is the current code:

Sub Totals()
Dim Client As Range
Dim Spend As Range
Dim Sales As Range

Set Client = Sheet1.Range("C7")
Set Spend = Sheet1.Range("E7")
Set Sales = Sheet1.Range("F7")

Do Until ActiveCell = "STOP"
If Client = "Program Total" Then
Spend = FORMULA TO ADD THE VARIABLE RANGE
Sales = FORMULA TO ADD THE VARIABLE RANGE
Client = Client.Offset(1, 0).Select
Spend = Spend.Offset(1, 0).Select
Sales = Sales.Offset(1, 0).Select
Else
Client = Client.Offset(1, 0).Select
Spend = Spend.Offset(1, 0).Select
Sales = Sales.Offset(1, 0).Select
End If

End Sub

Second Question:
Is there a better way to do this? My experience is that there always is...

Thanks!

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
Named ranges scope / workbook/worksheet level named ranges- changeswith variable use... christian_spaceman Excel Programming 3 December 24th 07 01:15 PM
Variable Ranges Erika Excel Worksheet Functions 1 November 30th 07 09:21 PM
Variable ranges igorek Excel Programming 5 November 17th 06 12:17 AM
Counting variable ranges and auto-summing variable ranges Father Guido[_5_] Excel Programming 2 March 29th 06 04:07 AM
Variable ranges John Contact Excel Worksheet Functions 1 June 17th 05 08:02 AM


All times are GMT +1. The time now is 03:04 AM.

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"