Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to sum Values in selected range?

Imagine a new worksheet and in the range B2:B6 you have the values 1
3 4 5. If you highlight this range, provided you have selected "SUM
from the right click menu on the statusbar, the result Sum = 25 appear
in the status bar.

So, in VBA, how do I capture that result!? I want to be able to selec
my range - Range("B2:B6").select - and then capture that sum of th
values within that range but I can't work out how to do it.

Yes I could loop through all the cells within the range building up th
calc but I must be able to use the status bar Auto Calculate featur
somehow....

Many thanks guys

Ba

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default How to sum Values in selected range?

Your answer is in the formula property.

Example:
Range("A1").Formula = "=SUM(B2:B6)"

You can also concatinate this string together like:

Range("A1").Formula = "=SUM(" & firstcell & ":" & _
lastcell & ")"

Also, take a look at the formulaR1C1 property for doing
formulas positional to the cell your putting the formula
into.


-----Original Message-----
Imagine a new worksheet and in the range B2:B6 you have

the values 1 2
3 4 5. If you highlight this range, provided you have

selected "SUM"
from the right click menu on the statusbar, the result

Sum = 25 appears
in the status bar.

So, in VBA, how do I capture that result!? I want to be

able to select
my range - Range("B2:B6").select - and then capture

that sum of the
values within that range but I can't work out how to do

it.

Yes I could loop through all the cells within the range

building up the
calc but I must be able to use the status bar Auto

Calculate feature
somehow....

Many thanks guys

Baz


---
Message posted from http://www.ExcelForum.com/

.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,089
Default How to sum Values in selected range?

Baz

in the immediate window:

?application.worksheetfunction.Sum(selection)

Regards

Trevor


"FastOneBaz " wrote in message
...
Imagine a new worksheet and in the range B2:B6 you have the values 1 2
3 4 5. If you highlight this range, provided you have selected "SUM"
from the right click menu on the statusbar, the result Sum = 25 appears
in the status bar.

So, in VBA, how do I capture that result!? I want to be able to select
my range - Range("B2:B6").select - and then capture that sum of the
values within that range but I can't work out how to do it.

Yes I could loop through all the cells within the range building up the
calc but I must be able to use the status bar Auto Calculate feature
somehow....

Many thanks guys

Baz


---
Message posted from http://www.ExcelForum.com/



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default How to sum Values in selected range?

I think you want

myVar = WorksheetFunction.SUM(Range("B2:B6"))

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"FastOneBaz " wrote in message
...
Imagine a new worksheet and in the range B2:B6 you have the values 1 2
3 4 5. If you highlight this range, provided you have selected "SUM"
from the right click menu on the statusbar, the result Sum = 25 appears
in the status bar.

So, in VBA, how do I capture that result!? I want to be able to select
my range - Range("B2:B6").select - and then capture that sum of the
values within that range but I can't work out how to do it.

Yes I could loop through all the cells within the range building up the
calc but I must be able to use the status bar Auto Calculate feature
somehow....

Many thanks guys

Baz


---
Message posted from http://www.ExcelForum.com/



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to sum Values in selected range?

Thanks, that works great. Excellent I'm well chuffed

--
Message posted from http://www.ExcelForum.com



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
List values based on different values selected maniarasan Excel Discussion (Misc queries) 7 June 4th 10 02:12 PM
SUMPRODUCT or SUMIF if any values in a range equal any values in another range PCLIVE Excel Worksheet Functions 3 July 15th 09 07:43 PM
Automatically clear values from a range of selected cells John Davies Excel Discussion (Misc queries) 1 June 28th 05 04:42 PM
Assigning values from a selected range to individual variables Dr. Schwartz[_3_] Excel Programming 5 January 27th 04 02:27 PM
Box around selected range Tom Ogilvy Excel Programming 1 September 7th 03 04:42 PM


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