LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Adding a selection of values and storing result in a variable

Continuing on and playing around, I have discovered another way by allocating
the sum of the range to a variable ready for use in further additional
calculations/functions within the code. (The €˜SumOfRange is the variable).

Sub Simka2()

Dim SumOfRange As Double

SumOfRange = Application.WorksheetFunction.Sum(Selection)

Debug.Print SumOfRange €˜Used to check the result in immediate window

' Additional code below
:
:
:
:
End Sub




"Simka" wrote:

Many thanks that helped a treat, it's exactly wanted I was after.

PS. I should have said:

....holding down the SHIFT or CTRL key and then.....

Simka


"Gary''s Student" wrote:

Here is a little macro that uses Z100 as a "helper" cell:

Sub simka()
With Range("Z100")
.Value = Application.WorksheetFunction.Sum(Selection)
.Copy
End With
End Sub

You can assign the macro to a button or give it a shortcut key.

After running the macro, click on some other cell and CNTRL-v or
Edit Paste

will depost the sum.
--
Gary''s Student - gsnu200804


"Simka" wrote:

This may have been asked before but - I regularly need to find the sum of a
(random) selection of values on a worksheet by selecting the range by and/or
holding down the SPACEBAR or CTRL key and then viewing the sum of the values
on the status bar. Idealy, I would like to press a button to start a macro to
add up all the values that have been selected and store the result in a
variable so that then this value can be pasted elsewhere. Any suggestions on
the coding?



 
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
Storing result of function directly in a variable instead of cell. Mak Excel Programming 4 March 7th 08 02:33 PM
Storing a selection from a combo box in a variable bony_tony Excel Programming 1 December 12th 06 10:45 PM
Storing a value to variable CLamar Excel Discussion (Misc queries) 0 June 16th 06 04:46 PM
Storing variable values in Excel worksheet Henry Stockbridge Excel Programming 3 April 25th 06 02:38 PM
Storing selection & using the saved selection adress later Ozgur Pars[_2_] Excel Programming 5 April 18th 06 12:01 PM


All times are GMT +1. The time now is 08:36 AM.

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"