PC Review


Reply
Thread Tools Rate Thread

Adding all numbers in a given range

 
 
Deecrypt
Guest
Posts: n/a
 
      23rd Jan 2007
Hi all,
Devising a macro that needs to add all the numbers up together in a
given range of cells i.e Range(ref1 &":"& ref2) and assign the total to
a given variable i.e total. Please let me know how I can do this.
I've tried to record a macro and copy details but that shows absolute
cell references whereas I'm working with relative cell references.
Have also looked thgrough the newsgroups and have not found something
specific to my query.

Thank you kindly
Deecrypt

 
Reply With Quote
 
 
 
 
Bob Phillips
Guest
Posts: n/a
 
      23rd Jan 2007
Dim cell As Range
For Each cell In Range(ref1 & ":" & ref2)
If IsNumeric(cell.Value) Then
total = total + cell.Value
End If
Next cell


--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)


"Deecrypt" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi all,
> Devising a macro that needs to add all the numbers up together in a
> given range of cells i.e Range(ref1 &":"& ref2) and assign the total to
> a given variable i.e total. Please let me know how I can do this.
> I've tried to record a macro and copy details but that shows absolute
> cell references whereas I'm working with relative cell references.
> Have also looked thgrough the newsgroups and have not found something
> specific to my query.
>
> Thank you kindly
> Deecrypt
>



 
Reply With Quote
 
Khurram
Guest
Posts: n/a
 
      23rd Jan 2007
Thank you Bob, Works like a charm.

Khurram

Bob Phillips wrote:
> Dim cell As Range
> For Each cell In Range(ref1 & ":" & ref2)
> If IsNumeric(cell.Value) Then
> total = total + cell.Value
> End If
> Next cell
>
>
> --
> ---
> HTH
>
> Bob
>
> (change the xxxx to gmail if mailing direct)
>
>
> "Deecrypt" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hi all,
> > Devising a macro that needs to add all the numbers up together in a
> > given range of cells i.e Range(ref1 &":"& ref2) and assign the total to
> > a given variable i.e total. Please let me know how I can do this.
> > I've tried to record a macro and copy details but that shows absolute
> > cell references whereas I'm working with relative cell references.
> > Have also looked thgrough the newsgroups and have not found something
> > specific to my query.
> >
> > Thank you kindly
> > Deecrypt
> >


 
Reply With Quote
 
Excelibur
Guest
Posts: n/a
 
      23rd Jan 2007
To avoid looping through all the cells, try this:

total = WorksheetFunction.Sum(Range(ref1 & ":" & ref2))


On 23 jan, 18:24, "Khurram" <knah...@gmail.com> wrote:
> Thank you Bob, Works like a charm.
>
> Khurram
>
> Bob Phillips wrote:
> > Dim cell As Range
> > For Each cell In Range(ref1 & ":" & ref2)
> > If IsNumeric(cell.Value) Then
> > total = total + cell.Value
> > End If
> > Next cell

>
> > --
> > ---
> > HTH

>
> > Bob

>
> > (change the xxxx to gmail if mailing direct)

>
> > "Deecrypt" <knah...@gmail.com> wrote in message
> >news:(E-Mail Removed)...
> > > Hi all,
> > > Devising a macro that needs to add all the numbers up together in a
> > > given range of cells i.e Range(ref1 &":"& ref2) and assign the total to
> > > a given variable i.e total. Please let me know how I can do this.
> > > I've tried to record a macro and copy details but that shows absolute
> > > cell references whereas I'm working with relative cell references.
> > > Have also looked thgrough the newsgroups and have not found something
> > > specific to my query.

>
> > > Thank you kindly
> > > Deecrypt


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding numbers based on Range Carla Microsoft Excel Worksheet Functions 2 18th Jun 2009 03:25 PM
Adding numbers in a range gd Microsoft Excel Programming 3 9th Feb 2009 08:49 PM
Adding variable range of numbers mwavra Microsoft Excel Worksheet Functions 6 16th Oct 2008 04:58 PM
adding range of numbers to if statement with three criteria =?Utf-8?B?TWlmdHk=?= Microsoft Excel Worksheet Functions 4 7th Nov 2007 11:18 AM
Re: Adding a range of numbers associated with various dates Dave O Microsoft Excel Misc 1 18th Jan 2007 03:31 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:14 AM.