Add every nth cell

Moonbeam111

Board Regular
Joined
Sep 24, 2018
Messages
94
Office Version
  1. 365
  2. 2010
I have a worksheet and in that worksheet I basically need to add the value of every nth cell onto a different cell that has the total of all those cells.

So in my case, I would like to be able to add every 9th cell in column O starting with Range("O15") continuing all the way down to Range("O1002) and adding the total of all those numbers to Range("H2").

I have a formula to do this that I put in cell H2:

Excel Formula:
=SUM(IF(MOD(ROW($O$1:$O$1002)-6,9)=0,$O$1:$O$1002,0))

But I would like to be able to do this in VBA because of other things I'm doing to my workbook and I'm not sure where to start.

Any assistance would be much appreciated.
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
I have a worksheet and in that worksheet I basically need to add the value of every nth cell onto a different cell that has the total of all those cells.

So in my case, I would like to be able to add every 9th cell in column O starting with Range("O15") continuing all the way down to Range("O1002) and adding the total of all those numbers to Range("H2").

I have a formula to do this that I put in cell H2:

Excel Formula:
=SUM(IF(MOD(ROW($O$1:$O$1002)-6,9)=0,$O$1:$O$1002,0))

But I would like to be able to do this in VBA because of other things I'm doing to my workbook and I'm not sure where to start.

Any assistance would be much appreciated.
This approach works.

VBA Code:
Public Sub subNth()
Dim lngSum As Long

  lngSum = Evaluate("SUM(IF(MOD(ROW($O$1:$O$1002)-6,9)=0,$O$1:$O$1002,0))")
  
  MsgBox lngSum
  
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,226,501
Messages
6,191,397
Members
453,655
Latest member
lasvegasbuffet

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top