split range into multiple range based on blank row for each range

Ali M

Active Member
Joined
Oct 10, 2021
Messages
330
Office Version
  1. 2019
  2. 2013
Platform
  1. Windows
Hi
I have many data contains blank row , should split data for each range based on end blank row
each range start data from first row and finish at blank row .
when split data should merge duplicates items and sum amounts for debit and credit and calculation by column BALANCE and I don't need any formula in column L
the result should be H:L.
every time I will add new data in columns A:D , should delete data H:L when run the macro every time .
I Have about 3500 rows .
AGGREGATE1.xlsm
ABCD
1DATEACCOUNT NAMEDEBIT CREDIT
201/03/2023CASH BALANCE200,000.00
303/03/2023CASH PR 2,000.00
403/03/2023CASH PR 15,000.00
509/03/2023CASH PR 500.00
613/03/2023CASH PR 10,000.00
713/03/2023CASH PR 15,000.00
814/03/2023CASH PR 500.00
919/03/2023CASH PR 500.00
1019/03/2023CASH PR 2,000.00
1105/03/2023CASH DM2,000.00
1210/03/2023CASH DM500.00
1315/03/2023CASH DM5,000.00
1415/03/2023CASH DM2,000.00
1515/03/2023CASH DM10,000.00
1618/03/2023CASH DM25,000.00
1719/03/2023CASH DM2,000.00
1807/04/2023EXPENSE ADMIN55000
1908/04/2023EXPENSE ADMIN10000
20
2125/03/2023PURCHASE10000
2229/03/2023PURCHASE5000
2309/04/2023STOCK1100000
2430/03/2023PURCHASE RETURNS2000
2531/03/2023PURCHASE RETURNS2000
2603/04/2023PURCHASE LOW 4000
2704/04/2023PURCHASE LOW 2200
2821/03/2023EXPENSE PR15,000.00
2921/03/2023EXPENSE PR20,000.00
3023/03/2023EXPENSE PR2,000.00
31
3224/03/2023SALES200000
3326/03/2023SALES1000
3427/03/2023SALES RETURNS2500
3528/03/2023SALES RETURNS1000
3601/04/2023SELLING LOW 2000
3702/04/2023SELLING LOW 1200
38
3905/04/2023STOCK70000
4006/04/2023STOCK130000
41
DAILY


result

AGGREGATE1.xlsm
ABCDEFGHIJKL
1DATEACCOUNT NAMEDEBIT CREDITITEMACCOUNT NAMEDEBIT CREDITBALANCE
201/03/2023CASH BALANCE200,000.001CASH BALANCE200,000.00200,000.00
303/03/2023CASH PR 2,000.002CASH PR 15,000.0030,500.00184,500.00
403/03/2023CASH PR 15,000.003CASH DM9,500.0037,000.00157,000.00
509/03/2023CASH PR 500.004EXPENSE ADMIN65,000.0092,000.00
613/03/2023CASH PR 10,000.00TOTAL224,500.00132,500.0092,000.00
713/03/2023CASH PR 15,000.00
814/03/2023CASH PR 500.00ITEMACCOUNT NAMEDEBIT CREDITBALANCE
919/03/2023CASH PR 500.001PURCHASE15,000.0015,000.00
1019/03/2023CASH PR 2,000.002STOCK1100,000.00115,000.00
1105/03/2023CASH DM2,000.003PURCHASE RETURNS4,000.00111,000.00
1210/03/2023CASH DM500.004PURCHASE LOW 6,200.00117,200.00
1315/03/2023CASH DM5,000.005EXPENSE PR37,000.00154,200.00
1415/03/2023CASH DM2,000.00TOTAL158,200.004,000.00154,200.00
1515/03/2023CASH DM10,000.00
1618/03/2023CASH DM25,000.00ITEMACCOUNT NAMEDEBITCREDITBALANCE
1719/03/2023CASH DM2,000.001SALES201,000.00-201,000.00
1807/04/2023EXPENSE ADMIN550002SALES RETURNS3,500.00-197,500.00
1908/04/2023EXPENSE ADMIN100003SELLING LOW 3,200.00-200,700.00
20TOTAL3,500.00204,200.00-200,700.00
2125/03/2023PURCHASE10000
2229/03/2023PURCHASE5000ITEMACCOUNT NAMEDEBITCREDITBALANCE
2309/04/2023STOCK11000001STOCK200,000.00200,000.00
2430/03/2023PURCHASE RETURNS2000TOTAL200,000.000.00200,000.00
2531/03/2023PURCHASE RETURNS2000
2603/04/2023PURCHASE LOW 4000
2704/04/2023PURCHASE LOW 2200
2821/03/2023EXPENSE PR15,000.00
2921/03/2023EXPENSE PR20,000.00
3023/03/2023EXPENSE PR2,000.00
31
3224/03/2023SALES200000
3326/03/2023SALES1000
3427/03/2023SALES RETURNS2500
3528/03/2023SALES RETURNS1000
3601/04/2023SELLING LOW 2000
3702/04/2023SELLING LOW 1200
38
3905/04/2023STOCK70000
4006/04/2023STOCK130000
41
DAILY
Cell Formulas
RangeFormula
L2,L23:L24,L20,L17,L14,L9,L6L2=J2-K2
L18:L19,L10:L13,L3:L5L3=L2+J3-K3
J6:K6J6=SUM(J2:J5)
J14:K14J14=SUM(J9:J13)
J20:K20J20=SUM(J17:J19)
J24:K24J24=SUM(J23:J23)
AGGREGATE1.xlsm
ABCDEFGHIJKL
1DATEACCOUNT NAMEDEBIT CREDITITEMACCOUNT NAMEDEBIT CREDITBALANCE
201/03/2023CASH BALANCE200,000.001CASH BALANCE200,000.00200,000.00
303/03/2023CASH PR 2,000.002CASH PR 15,000.0030,500.00184,500.00
403/03/2023CASH PR 15,000.003CASH DM9,500.0037,000.00157,000.00
509/03/2023CASH PR 500.004EXPENSE ADMIN65,000.0092,000.00
613/03/2023CASH PR 10,000.00TOTAL224,500.00132,500.0092,000.00
713/03/2023CASH PR 15,000.00
814/03/2023CASH PR 500.00ITEMACCOUNT NAMEDEBIT CREDITBALANCE
919/03/2023CASH PR 500.001PURCHASE15,000.0015,000.00
1019/03/2023CASH PR 2,000.002STOCK1100,000.00115,000.00
1105/03/2023CASH DM2,000.003PURCHASE RETURNS4,000.00111,000.00
1210/03/2023CASH DM500.004PURCHASE LOW 6,200.00117,200.00
1315/03/2023CASH DM5,000.005EXPENSE PR37,000.00154,200.00
1415/03/2023CASH DM2,000.00TOTAL158,200.004,000.00154,200.00
1515/03/2023CASH DM10,000.00
1618/03/2023CASH DM25,000.00ITEMACCOUNT NAMEDEBITCREDITBALANCE
1719/03/2023CASH DM2,000.001SALES201,000.00-201,000.00
1807/04/2023EXPENSE ADMIN550002SALES RETURNS3,500.00-197,500.00
1908/04/2023EXPENSE ADMIN100003SELLING LOW 3,200.00-200,700.00
20TOTAL3,500.00204,200.00-200,700.00
2125/03/2023PURCHASE10000
2229/03/2023PURCHASE5000ITEMACCOUNT NAMEDEBITCREDITBALANCE
2309/04/2023STOCK11000001STOCK200,000.00200,000.00
2430/03/2023PURCHASE RETURNS2000TOTAL200,000.000.00200,000.00
2531/03/2023PURCHASE RETURNS2000
2603/04/2023PURCHASE LOW 4000
2704/04/2023PURCHASE LOW 2200
2821/03/2023EXPENSE PR15,000.00
2921/03/2023EXPENSE PR20,000.00
3023/03/2023EXPENSE PR2,000.00
31
3224/03/2023SALES200000
3326/03/2023SALES1000
3427/03/2023SALES RETURNS2500
3528/03/2023SALES RETURNS1000
3601/04/2023SELLING LOW 2000
3702/04/2023SELLING LOW 1200
38
3905/04/2023STOCK70000
4006/04/2023STOCK130000
41
DAILY
Cell Formulas
RangeFormula
L2,L23:L24,L20,L17,L14,L9,L6L2=J2-K2
L18:L19,L10:L13,L3:L5L3=L2+J3-K3
J6:K6J6=SUM(J2:J5)
J14:K14J14=SUM(J9:J13)
J20:K20J20=SUM(J17:J19)
J24:K24J24=SUM(J23:J23)
M(J17:J19)[/XD][/XR][XR][XD]J24:K24[/XD][XD=fw:b]J24[/XD][XD]=SUM(J23:J23)[/XD][/XR][/RANGE]
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Try the following macro:


Excel Formula:
Sub SplitRange()
  Dim sh As Worksheet
  Dim dic As Object
  Dim a As Variant, b As Variant
  Dim i As Long, nRow As Long, y As Long
  Dim dbt As Double, cdt As Double
  Dim ar As Range
 
  Application.ScreenUpdating = False
 
  Set sh = Sheets("DAILY")
  Set dic = CreateObject("Scripting.Dictionary")
 
  a = sh.Range("B2:D" & sh.Range("B" & Rows.Count).End(3).Row + 1).Value
  ReDim b(1 To UBound(a, 1) * 3, 1 To 5)
  sh.Range("H:L").Clear
 
'merge duplicates items and sum amounts for debit and credit
  y = 1
  For i = 1 To UBound(a)
    If a(i, 1) = "" Then
      dic.RemoveAll
      y = y + 3
    Else
      If Not dic.exists(a(i, 1)) Then
        y = y + 1
        nRow = y
        dic(a(i, 1)) = nRow
      Else
        nRow = dic(a(i, 1))
      End If
      b(nRow, 1) = dic.Count
      b(nRow, 2) = a(i, 1)
      b(nRow, 3) = b(nRow, 3) + a(i, 2)
      b(nRow, 4) = b(nRow, 4) + a(i, 3)
    End If
  Next
 
'Balance and Total
  For i = 2 To y
    If b(i, 1) = "" And b(i - 1, 1) <> "" Then
      b(i, 2) = "TOTAL"
      b(i, 3) = dbt
      b(i, 4) = cdt
      b(i, 5) = dbt - cdt
      dbt = 0
      cdt = 0
    Else
      If b(i, 1) <> "" Then
        b(i, 5) = Val(b(i - 1, 5)) + b(i, 3) - b(i, 4)
      End If
      dbt = dbt + b(i, 3)
      cdt = cdt + b(i, 4)
    End If
  Next
  Range("H1").Resize(UBound(b, 1), UBound(b, 2)).Value = b
 
'Format Cells
  For Each ar In sh.Range("H2:H" & sh.Range("H" & Rows.Count).End(3).Row). _
    SpecialCells(xlCellTypeConstants).Areas
    With ar.Offset(-1).Resize(ar.Rows.Count + 1, 5)
      .Borders.LineStyle = 1
      .Borders.ColorIndex = 16
    End With
    With ar.Offset(-1).Resize(1, 5)
      .Value = Array("ITEM", "ACCOUNT NAME", "DEBIT", "CREDIT", "BALANCE")
      .Font.Color = sh.Range("D1").Font.Color
      .Font.Bold = True
      .Interior.Color = sh.Range("D1").Interior.Color
    End With
    With ar.Cells(1).Offset(ar.Rows.Count, 1)
      .Font.Color = vbRed
      .Font.Bold = True
      .Interior.Color = vbYellow
      .Resize(1, 4).Borders.LineStyle = 1
      .Resize(1, 4).Borders.ColorIndex = 16
    End With
  Next
  With sh.Range("H:L")
    .EntireColumn.AutoFit
    .HorizontalAlignment = xlCenter
  End With
  sh.Range("J:L").NumberFormat = "#,##0.00;;;"
 
  Application.ScreenUpdating = True
End Sub


Regards
Dante Amor

The good listener few words.
Al buen entendedor, pocas palabras.
-Dicho popular-
 
Upvote 1
Solution
thanks
seem some headers and balance column for specific range are missed !
AGGREGATE1.xlsm
HIJKL
1ITEMACCOUNT NAME
21CASH BALANCE200,000.00200,000.00
32CASH PR 15,000.0030,500.00184,500.00
43CASH DM9,500.0037,000.00157,000.00
54EXPENSE ADMIN65,000.0092,000.00
6TOTAL224,500.00132,500.0092,000.00
7
8ITEMACCOUNT NAME
91PURCHASE15,000.0015,000.00
102STOCK1100,000.00115,000.00
113PURCHASE RETURNS4,000.00111,000.00
124PURCHASE LOW 6,200.00117,200.00
135EXPENSE PR37,000.00154,200.00
14TOTAL158,200.004,000.00154,200.00
15
16ITEMACCOUNT NAME
171SALES201,000.00
182SALES RETURNS3,500.00
193SELLING LOW 3,200.00
20TOTAL3,500.00204,200.00
21
22ITEMACCOUNT NAME
231STOCK200,000.00200,000.00
24TOTAL200,000.00200,000.00
DAILY
 
Upvote 0
After many tests and checking that everything was ok, and after more than 80 lines of code, just the last line, I no longer checked that the data was displayed correctly on the screen.
(There are always details in macros and even more so when it comes to cell formats)

Just change this line:
VBA Code:
sh.Range("J:L").NumberFormat = "#,##0.00;;;"

For this line:
VBA Code:
sh.Range("J:L").NumberFormat = "#,##0.00;-#,##0.00;;@"

The best hunter loses the hare
Al mejor cazador se le va la liebre
-Dicho popular-
 
Upvote 0
now it works greatly (y)
I grateful for you :)
thank you so much ;)
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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