+ Reply to Thread
Results 1 to 11 of 11

Thread: find and total values

  1. #1
    Valued Forum Contributor
    Join Date
    07-10-2008
    Location
    UK
    Posts
    219

    find and total values

    Hi guys.

    Starting with Cell B4, every 20 cells downwards I have a number.

    I would like a code which will give me a total of all of these numbers.

    So B4, B24, B44, B64....and so on.

    Any ideas?
    Last edited by twofootgiant; 07-04-2011 at 09:32 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2003
    Posts
    2,488

    Re: find and total values

    hi, twofootgiant, I hope I understood your question right
    Attached Files Attached Files

  3. #3
    Valued Forum Contributor
    Join Date
    07-10-2008
    Location
    UK
    Posts
    219

    Re: find and total values

    Hi watersev

    Thanks for your resposne but I dont hink you understood correctly.

    I have a sheet with lots of data. every 20 rows in column B there is a number. I need to find the total sum of those numbers.

    So..the cells i need to add up are B4, B24, B44, B64...and so on....

    The result will go into cell A1 of sheet2

  4. #4
    Valued Forum Contributor
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2003
    Posts
    2,488

    Re: find and total values

    please check attachment, run code "test", result in in E3

    PS. In order to understand you correct it's good to have a file sample ...
    Attached Files Attached Files

  5. #5
    Valued Forum Contributor
    Join Date
    07-10-2008
    Location
    UK
    Posts
    219

    Re: find and total values

    Hi watersev, thanks for the reply.

    How would I modify this so that it would add up the totals on one hidden sheet and place the total value on another hidden sheet?

  6. #6
    Valued Forum Contributor
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2003
    Posts
    2,488

    Re: find and total values

    please check attachment, run code "test" and make Sheet1 and Sheet2 visible to check result.

    The code sums values on hidden sheet("Sheet1") and places result in hidden sheet("Sheet2"). There are two visible sheets showing layout of hidden sheets.
    Attached Files Attached Files

  7. #7
    Forum Guru mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    2,998

    Re: find and total values

    This formula should do that.
    =SUMPRODUCT(--(MOD(ROW(B4:B400), 20)=4),B4:B400)
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  8. #8
    Valued Forum Contributor
    Join Date
    07-10-2008
    Location
    UK
    Posts
    219

    Re: find and total values

    Hi watersev,

    I am trying to modify the code to get the totals of multiple columns. But the totals do not add u correctly.

    What am I doing wrong?

    Private Sub CommandButton8_Click()
    
    Dim i As Long, temp As Double, myrange As Range
    'info1
    With Sheets("Master"): Set myrange = .Range(.[b3], .Cells(Rows.Count, "b").End(xlUp))
    For i = 2 To myrange.Cells.Count Step 20: temp = temp + myrange(i): Next
    Sheets("Stats").[b7] = temp: End With:
    'info2
    With Sheets("Master"): Set myrange = .Range(.[c3], .Cells(Rows.Count, "c").End(xlUp))
    For i = 2 To myrange.Cells.Count Step 20: temp = temp + myrange(i): Next
    Sheets("Stats").[c7] = temp: End With:
    'info3
    With Sheets("Master"): Set myrange = .Range(.[d3], .Cells(Rows.Count, "d").End(xlUp))
    For i = 2 To myrange.Cells.Count Step 20: temp = temp + myrange(i): Next
    Sheets("Stats").[d7] = temp: End With:
    'info4
    With Sheets("Master"): Set myrange = .Range(.[e3], .Cells(Rows.Count, "e").End(xlUp))
    For i = 2 To myrange.Cells.Count Step 20: temp = temp + myrange(i): Next
    Sheets("Stats").[e7] = temp: End With:
    'info5
    With Sheets("Master"): Set myrange = .Range(.[f3], .Cells(Rows.Count, "f").End(xlUp))
    For i = 2 To myrange.Cells.Count Step 20: temp = temp + myrange(i): Next
    Sheets("Stats").[f7] = temp: End With:
    'info6
    With Sheets("Master"): Set myrange = .Range(.[g3], .Cells(Rows.Count, "g").End(xlUp))
    For i = 2 To myrange.Cells.Count Step 20: temp = temp + myrange(i): Next
    Sheets("Stats").[g7] = temp: End With:
    
    Unload Me
    Sheets("Stats").Visible = True
    Sheets("Stats").Select
    
    End Sub

  9. #9
    Valued Forum Contributor
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2003
    Posts
    2,488

    Re: find and total values

    please check attachment example, run code "test".

    Would not it be easier to post your workbook sample?
    Attached Files Attached Files

  10. #10
    Valued Forum Contributor
    Join Date
    07-10-2008
    Location
    UK
    Posts
    219

    Re: find and total values

    Hi watersev,

    please find attached an example of what I am trying to do. this should show how the results should look after the code has been run.

    Thanks
    Attached Files Attached Files

  11. #11
    Valued Forum Contributor
    Join Date
    07-10-2008
    Location
    UK
    Posts
    219

    Re: find and total values

    dont worry guys, worked it out myself

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0