Consulting

Results 1 to 3 of 3

Thread: Not Getting Sum Result From All Sheets

  1. #1
    VBAX Regular
    Joined
    Sep 2021
    Location
    INDIA
    Posts
    18
    Location

    Not Getting Sum Result From All Sheets

    Hi Excel Friends

    I have applied this vba to get sum result from all sheets into main sheet in workbook here what the problem i have getting when i run this vba i will getting sum result from one sheet only

    I Need to get Total Sum Result From all Sheet the Range("D3 to D7") to Cell ("B2") in main sheet


    This is the Code i applied



    
    Sub SumMul()
    
    
       Dim wb As Workbook, ws As Worksheet, ar, i As Double
       
       Set wb = ThisWorkbook
       ReDim ar(1 To wb.Sheets.Count, 1 To 1)
       
       
       For Each ws In wb.Sheets
            If ws.Name <> "main" Then
                i = i + 1
                ar(i, 1) = Application.WorksheetFunction.Sum(ws.Range("D3:D7"))
            End If
       Next
       
       wb.Sheets("main").Range("B2").Value = ar
       
    
    
    End Sub

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,875
    Depending on what you want, you can try replacing your:
    wb.Sheets("main").Range("B2").Value = ar
    with:
    wb.Sheets("main").Range("B2").Value = Application.Sum(ar)
    if you want a single total in a single cell


    or:
    wb.Sheets("main").Range("B2").Resize(i).Value = ar
    if you want a row per sheet total starting at cell B2.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    VBAX Regular
    Joined
    Sep 2021
    Location
    INDIA
    Posts
    18
    Location
    Thank you so much @p45cal

Tags for this Thread

Posting Permissions

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