LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Macro to add a variable list

G'day all

I need a macro that adds (sums) a variable list of numbers.

The data could be
A3 40
A4 5
A5 19
A6 36

I'm after a macro that if the cursor is in B6, the total will be given of 100.

I move the cursor to another list (anywhere in the workbook) and it will
give the answer to that list.

Eg move cursor to B18, hit the macro which gives the answer (in B18) as 205.

A13 23
A14 4
A15 67
A16 52
A17 12
A18 47

So far I've come up with the following code;-

Dim MyRange As Range
ActiveCell.Offset(0, -1).Select
Set MyRange = Range(Selection, Selection.End(xlUp)).Select
ActiveCell.FormulaR1C1 = "=SUM([" & MyRange & "])"

But it gives the following error at the "Set MyRange" line
"Runtime Error 424 Object Required"

I also suspect that the "Activecell.formula" line is going to give me
problems as well.
Basically, I want to sum the range and that range will be of variable length.

Any suggestions???? The code doesn't have to follow what I've done. As long
as it works.

Thanks in advance

PS As most of you will have deduced by now, I know absolutely nothing about
VBA programming (- but I'm learning :))

 
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
Variable Validation List Ananth Excel Discussion (Misc queries) 2 June 1st 09 12:19 PM
drop down list variable Steve Excel Discussion (Misc queries) 2 September 14th 06 10:57 PM
Variable List Box Range peter_rivera[_4_] Excel Programming 10 June 30th 05 01:39 AM
Macro Creating Variable and using variable in a SQL statement Jimmy Excel Programming 4 October 25th 04 02:36 AM
Variable drop down list Rob Excel Programming 0 September 16th 04 05:51 PM


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