Over flow when try get last TOTAL row across sheets

Alaa mg

Active Member
Joined
May 29, 2021
Messages
378
Office Version
  1. 2019
hello
first this original code from this thread
create list by extract amounts for the last row for each sheet name
but I need modifying by get the last total row for each sheet , my problem after getting the last TOTAL for each sheet in BALANCES sheet should also insert TOTAL row to sum for all of sheets, but it shows overflow error as I comment out in theses the lines
VBA Code:
'ttl = a(1, 3) + ttl
 'tt2 = a(1, 4) + tt2
  'tt3 = a(1, 5) + tt3
VBA Code:
Option Explicit
Option Compare Text
Sub test1()
Dim i%, lrow%, k%, ttl%, tt2%, tt3%
Dim a()
Dim b()
ReDim b(1 To 10000, 1 To 6)

Sheets("BALANCES").[a2:F10000].Clear


For i = 1 To Worksheets.Count
      With Sheets(i)
            If Sheets(i).Name <> "BALANCES" Then 'Loop except balances sheet
             lrow = .Cells(Rows.Count, "e").End(xlUp).Row 'Find the last row of the sheets value
             a = .Range(.Cells(lrow, "A"), .Cells(lrow, "e")).Value 'Store last row into array
             k = k + 1
             b(k, 1) = k
             b(k, 2) = "OPENING BALANCE " & Date 'Date value
             b(k, 3) = Sheets(i).Name
             b(k, 4) = a(1, 3)
              b(k, 5) = a(1, 4)
             b(k, 6) = a(1, 5) '
              'Balance Value
             ' ttl = a(1, 3) + ttl
             ' tt2 = a(1, 4) + tt2
             'tt3 = a(1, 5) + tt3
             End If
      End With
   
Next i
With Sheets("BALANCES")
    .[a2].Resize(UBound(b, 1), UBound(b, 2)).Value = b 'Call out Array
    lrow = .Cells(Rows.Count, "a").End(xlUp).Row + 1
    .Cells(lrow, "A").Value = "TOTAL"
    .Cells(lrow, "d").Value = ttl
    .Cells(lrow, "E").Value = tt2
    .Cells(lrow, "F").Value = tt3
End With
 
End Sub

ALL.xlsm
ABCDE
1DATEDescribeDEBITCREDITBALANCE
205/01/2022NOT PAID12331233
306/01/2022NOT PAID12332466
407/01/2022PAID2000466
508/01/2022PAID40066
6TOTAL2,466.00240066.00
ALA
Cell Formulas
RangeFormula
C6:D6C6=SUM(C2:C5)
E6E6=C6-D6


ALL.xlsm
ABCDE
1DATEDescribeDEBITCREDITBALANCE
208/01/20220
309/01/2022NOT PAID20002000
411/01/2022NOT PAID200010003000
511/01/2022NOT PAID200040001000
6TOTAL600050001000
MN
Cell Formulas
RangeFormula
C6:D6C6=SUM(C3:C5)


ALL.xlsm
ABCDEF
1ITEMDETAILESNAMESDEBITCREDITBALANCE
2
3
4
BALANCES


result
ALL.xlsm
ABCDEF
1ITEMDETAILESNAMESDEBITCREDITBALANCE
2OPENING BALANCE 11/07/2023ALA24662,400.0066.00
3OPENING BALANCE 11/07/2023MN60005,000.001,000.00
4TOTAL84667,400.001,066.00
BALANCES
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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