Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Value Change Range of Sum in Another Cell

How would you program a number in a cell that would affect a SUM range in
another cell.

A1 = 2, then
A2 = Sum(B1...C1)

A1 = 5, then
A2 = SUM(B1...F1)


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Value Change Range of Sum in Another Cell

you can make it only using formula & function.
if programming it, you can do it as following:

Sub sumup()

Dim rngSum As Range
Dim rngB1 As Range
Dim a1 As Long

a1 = Sheet1.Range("A1").Value
Set rngB1 = Sheet1.Range("B1")
Set rngSum = Sheet1.Range(rngB1, rngB1.Offset(0, a1 - 1))

Debug.Print rngSum.Address
Debug.Print Application.WorksheetFunction.Sum(rngSum)

End Sub

"Al Franz" wrote:

How would you program a number in a cell that would affect a SUM range in
another cell.

A1 = 2, then
A2 = Sum(B1...C1)

A1 = 5, then
A2 = SUM(B1...F1)



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Value Change Range of Sum in Another Cell

On Apr 17, 8:55 pm, "Al Franz" wrote:
How would you program a number in a cell that would affect a SUM range in
another cell.


In A2, use the formula "=IF(A1 = 2,Sum(B1:C1), IF(A1 =
5,SUM(B1:F1),))"
This will make A2 = 0 if A1 is neither 2 nor 5.
If you use a macro, it will only be recalculated when the macro is
run. When you use a formula, the calculation is dynamic.

Cheers,
David

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
if then, change value of a cell range jo8502 New Users to Excel 1 October 28th 10 09:34 PM
Change Range using value in cell joecrabtree Excel Programming 2 December 8th 06 09:33 AM
How do I change cell color based upon data range within the cell? Chris Sanders Excel Worksheet Functions 1 March 6th 06 08:59 PM
How do I change a cell range with a reference cell? Danneskjold Excel Discussion (Misc queries) 2 August 11th 05 07:37 PM
Change cell colour for a cell or range within a predefined range Martin[_21_] Excel Programming 2 May 23rd 05 06:16 PM


All times are GMT +1. The time now is 08:27 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"