Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9225917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:41:55+00:00 2026-06-18T04:41:55+00:00

Im trying to sum the values within columns, which are separated by blocks, within

  • 0

Im trying to sum the values within columns, which are separated by blocks, within a dataset. The loops seem to be iterating correctly but the values within the loop “a” that output within the immediate window are not what I expected; it seems to be referencing 1 cell in column A, 5x. The script contains comments describing what I’m trying to achieve.

Sub sumCells()

Dim i, r, a, numObs As Integer
Dim Fa, Fb, Fc, Fd, Fe As Long

numObs = 10

Dim subStart As Integer

'loop to separate data into "blocks" of 10 rows (numObs). Step function used
'to contain loops below within each block. starts at 2 due to headers
For subStart = 2 To sheet1.UsedRange.Rows.Count Step numObs

   'loop to reference the rows within the subStart loop block
    For r = 2 To numObs

      'Loop to reference columns 1 through 5 (ideally I'd like to be able to
       'have this reference the actual column index so i dont have to
       'include more lines above to arrange the data accordingly
        For a = 1 To 5

           'this section is supposed to sum the values within each column
           'in this case, columns 1 to 5, within the rows specified above
           Fa = WorksheetFunction.Sum(Cells(r, 1))
           Fb = WorksheetFunction.Sum(Cells(r, 2))
           Fc = WorksheetFunction.Sum(Cells(r, 3))
           Fd = WorksheetFunction.Sum(Cells(r, 4))
           Fe = WorksheetFunction.Sum(Cells(r, 5))

       Next a

  Next r

Next subStart

End Sub

sample of the data, data starts on row 2, headers not included:

    0   4   6   8   10  762 857 997
  643   6   9   12  15  739 775 1084
  784   8   12  16  20  938 828 968
 1235   10  15  20  25  832 827 751
  809   12  18  24  30  759 131 1085
 1373   14  21  28  35  589 102 900
 1300   16  24  32  40  656 798 962
  901   18  27  36  45  782 812 786
  761   20  30  40  50  706 951 741
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T04:41:57+00:00Added an answer on June 18, 2026 at 4:41 am

    Assuming you want to sum each block of ten in each column and print that to the immediate window this code should work:

    Sub sumcols()
    
    Dim blocks As Integer
    Dim Fa As Long, Fb As Long, Fc As Long, Fd As Long, Fe As Long
    Dim i As Long, j As Long
    
    blocks = 9
    
    For i = 2 To Sheets("sheet1").Range("A1048576").End(xlUp).Row Step blocks + 1 'A1048576' will need to be changed if excel version older than '07
        'get sums for columns a through e for block starting with row i
    
        Fa = Application.WorksheetFunction.Sum(Sheets("sheet1").Range("A" & i & ":A" & i + blocks))
        Fb = Application.WorksheetFunction.Sum(Sheets("sheet1").Range("B" & i & ":B" & i + blocks))
        Fc = Application.WorksheetFunction.Sum(Sheets("sheet1").Range("C" & i & ":C" & i + blocks))
        Fd = Application.WorksheetFunction.Sum(Sheets("sheet1").Range("D" & i & ":D" & i + blocks))
        Fe = Application.WorksheetFunction.Sum(Sheets("sheet1").Range("E" & i & ":E" & i + blocks))
    
        'print values to immediate window
        Debug.Print Fa
        Debug.Print Fb
        Debug.Print Fc
        Debug.Print Fd
        Debug.Print Fe
    
    Next i
    
    End Sub
    

    Edit:

    to make the columns iterate as well use:

    (Fa will return the sum for every column in this case)

    Sub sumcols()
    
    Dim blocks As Integer
    Dim Fa As Long, Fb As Long, Fc As Long, Fd As Long, Fe As Long
    Dim i As Long, j As Long
    Dim currange As Range
    
    blocks = 9
    
    For i = 2 To Sheets("sheet1").Range("A1048576").End(xlUp).Row Step blocks + 1 'A1048576' will need to be changed if excel version older than '07
        'get sums for columns a through e for block starting with row i
    
        For j = 1 To 5 'iterate through columns
    
        'get range to sum (first range will be A2:A12)
        Set currange = Sheets("sheet1").Range(Sheets("sheet1").Cells(i, j), Sheets("sheet1").Cells(i + blocks, j))
    
        Fa = Application.WorksheetFunction.Sum(currange) 'Fa will return the sum for each column for each block
    
        'print values to immediate window
        Debug.Print Fa
    
        Next j
    
    Next i
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to add two decimal values but the returned sum is pure
I'm trying to find the sum of input values within multiple sections. I've put
I'm trying sum many values from radio buttons, but I'm with some problems in
I'm trying to find the sum of specific values within a table, using SQL.
I am trying to sum the values of a column within a table and
I'm trying to write a scala function which will recursively sum the values in
I am trying to sum values in a for loop with C. The initial
Im trying to do a sum of values i get from id but it
I am trying to sum a list of numbers in Jess, but I am
i'm trying to sum up values from one record (A) then add it to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.