+ Reply to Thread
Results 1 to 4 of 4

sum column in non blank sheets of 52 total

  1. #1
    Registered User
    Join Date
    07-13-2022
    Location
    Ga
    MS-Off Ver
    2010
    Posts
    25

    sum column in non blank sheets of 52 total

    i have a workbook with 52 sheets i can find the none blank worsheets.
    i need to total several column and put on a summary sheet.
    here is my code so far. tried many ways but getting error or wrong results at this line.

    Sld = WorksheetFunction.Sum(ws.Cells(8), (ws.Cells(8)))



    Sub Test_Totals_Sheets()
    Dim r As String
    Dim wbk As Workbook
    Dim ws As Worksheet
    Dim lastRow1 As Long
    Dim lastsheet As Long

    Dim Sold As Double 'Sold coumn
    Dim Subtotal As Double 'Subtotal column


    Dim Sld As Long ' SOLD
    Dim subT As Long 'Subtotal

    Dim Rng As Range

    Dim i As Long
    Dim Ntext As String

    r = 1
    Dim Sheet As String
    Set wbk = Workbooks("2023-Weeks-Test.xlsm")
    ' Find number of worksheets in workbook
    lastsheet = wbk.Sheets.Count

    Set ws = wbk.Worksheets("Week-" + r)

    'find last row
    lastRow1 = ws.Cells(Rows.Count, 1).End(xlUp).Row


    For i = 1 To 52

    Set wbk = Workbooks("2023-Weeks-Test.xlsm")
    Set ws = wbk.Worksheets("Week-" + r)

    If ws.Cells(1, 1) <> "" Then
    Worksheets("Week-" + r).Select
    Sld = 0
    Sold = 0

    lastRow1 = ws.Cells(Rows.Count, 1).End(xlUp).Row

    Sld = WorksheetFunction.Sum(ws.Cells(8), (ws.Cells(8)))

    MsgBox ("Sold Total =" & Sold)
    'do it here sheet is not blank
    lastRow1 = ws.Cells(Rows.Count, 1).End(xlUp).Row
    Ntext = lastRow1
    MsgBox ("NOT Blank Week-" + r)
    MsgBox ("last row is " + Ntext)
    Else

    'do it here if sheet is blank
    MsgBox ("is Blank week " + r)

    End If

    r = r + 1

    Next i




    End Sub

  2. #2
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: sum column in non blank sheets of 52 total

    Ws.cells(8) refers to only the row number of a cell. If you are trying to select a cell, say A8, you’ll need to use ws.cells(8,1). Also, if you are trying to get the sum of a range, say sum(Range(“A8:E8”)), that should be written as sum(ws.Range(ws.cells(8,1),ws.cells(8,5))). I hope this helps.

  3. #3
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Exclamation Re: sum column in non blank sheets of 52 total


    Hi maniacb !

    As Ws.Cells(8) is cell H1 of Ws … And yes its original codeline try to sum only H1 which has no sense …

  4. #4
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,361

    Re: sum column in non blank sheets of 52 total

    Worth remembering that if sheets are named with numbers on the end sequentially then you can sum the columns in all sheets with a formula like:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    and
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    You may find it easier to do it this way
    If things don't change they stay the same

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Google Sheets: Display Grand Total only when a column have value greater than 0
    By rohyl in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 1
    Last Post: 08-29-2022, 02:35 AM
  2. Replies: 2
    Last Post: 05-28-2022, 02:19 PM
  3. Replies: 2
    Last Post: 03-23-2021, 12:32 PM
  4. [SOLVED] Pivot to show only Non-Zero/blank field and total for Column
    By jp16 in forum Excel Charting & Pivots
    Replies: 10
    Last Post: 08-29-2017, 08:27 AM
  5. Replies: 0
    Last Post: 06-08-2015, 03:09 PM
  6. Replies: 6
    Last Post: 01-08-2014, 01:56 PM
  7. Creating a macro to insert a blank row and total sums in a new column
    By volleyballtigger in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-23-2013, 10:42 AM

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.6.0 RC 1