PC Review


Reply
Thread Tools Rate Thread

Creating sum formula using vba

 
 
QB
Guest
Posts: n/a
 
      5th May 2009
I need to sum every forth row between a start and end row. When I record a
macro, I get

"SUM(R[-60]C,R[-56]C,R[-52]C,R[-48],....,R[-4]C)"

If I know that I need to sum every forth row from row 3 to 59 in column E of
the active worksheet, how would I program this? I don't quite get the R[]C
format created by the macro recording.

Thank you,

QB
 
Reply With Quote
 
 
 
 
Ken
Guest
Posts: n/a
 
      5th May 2009
try this

firstRow = 10
lastRow = 100
incr = 4

total = 0

for i=firstRow to lastRow step incr
total = total + cells(i,col).value 'col = column number
next i

cells(row,col).value = total 'put your answer somewhere



"QB" wrote:

> I need to sum every forth row between a start and end row. When I record a
> macro, I get
>
> "SUM(R[-60]C,R[-56]C,R[-52]C,R[-48],....,R[-4]C)"
>
> If I know that I need to sum every forth row from row 3 to 59 in column E of
> the active worksheet, how would I program this? I don't quite get the R[]C
> format created by the macro recording.
>
> Thank you,
>
> QB

 
Reply With Quote
 
dan dungan
Guest
Posts: n/a
 
      5th May 2009
I found this thread from 2003:

Dan
_______________________________________________
Newsgroups: microsoft.public.excel.programming
From: "Florian Müller" <werkstudent.icmi...@mch.siemens.de>
Date: Fri, 4 Apr 2003 11:59:52 +0200
Local: Fri, Apr 4 2003 2:59 am
Subject: Sum every fourth row.

Hi!

I've got an Spreadsheet where i'd like to sum every fourth row,
starting
with the cell G5.
so:
SUM(G5+G9+G13+...+Gn)
SUM(H5+H9+H13+...+Hn)
..
..
..
SUM(Col5+Col9+...+Coln)
The problem is, that i have about 1000 records, so it would much work
to
click on every cell i need.
Which VBA code do i need?

Thanx
Flo

Newsgroups: microsoft.public.excel.programming
From: "Monika Weber" <Monika.We...@MVPs.org>
Date: Fri, 4 Apr 2003 12:17:04 +0200
Local: Fri, Apr 4 2003 3:17 am
Subject: Re: Sum every fourth row.

Hi Flo,

maybe something like this can help you:

Sub test()
Dim i As Integer
Dim dblSum As Double
For i = 1 To ActiveSheet.Range("G1:G20"). _
count Step 4
dblSum = dblSum + Cells(1, i)
Next i
MsgBox dblSum
End Sub

--
Es liebs Grüessli
Monika Weber [Microsoft MVP für Excel]
http://www.jumper.ch / http://excel.codebooks.de

Newsgroups: microsoft.public.excel.programming
From: "Arvi Laanemets" <a...@tarkon.ee>
Date: Fri, 4 Apr 2003 13:36:39 +0300
Local: Fri, Apr 4 2003 3:36 am
Subject: Re: Sum every fourth row.

Hi/Hallo

Ich denke dass hier ist wofür Du suchst (n=100)!
=SUMPRODUCT((MOD(ROW(G5:G100)-1;4)=0)*G5:G100)

Arvi Laanemets

Newsgroups: microsoft.public.excel.programming
From: Alan Beban <be...@postoffice.pacbell.net>
Date: Fri, 04 Apr 2003 10:44:42 -0800
Local: Fri, Apr 4 2003 11:44 am
Subject: Re: Sum every fourth row.

A different approach for any who use the functions from the file at
http://home.pacbell.net/beban:

=SUM(ArrayAlternates(ArrayAlternates(G5:G100)))

Alan Beban

Newsgroups: microsoft.public.excel.programming
From: "orthnerk" <orthn...@telusplanet.net>
Date: Fri, 4 Apr 2003 13:28:11 -0800
Local: Fri, Apr 4 2003 2:28 pm
Subject: Sum every fourth row.

have you looked at maybe the subtotals function. Is the
data the same for each of the four rows you will be
summing? Subtotals work like a charm and they are quickly
removable if your data changes.

 
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
Creating a formula =?Utf-8?B?VGNreVRpbmE=?= Microsoft Excel Worksheet Functions 3 3rd Oct 2007 01:43 PM
Re: Creating a formula Bob Phillips Microsoft Excel Misc 2 20th Dec 2006 02:07 AM
need help creating formula enixma@gmail.com Microsoft Excel Worksheet Functions 2 8th Dec 2006 07:26 PM
Creating a formula that references the formula in another cell robin.chappell Microsoft Excel Misc 1 21st Aug 2004 09:17 PM
I need some help creating a formula Philea_92 Microsoft Excel Discussion 3 17th Dec 2003 01:18 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:42 PM.