Macro to change way of showing data by transporting for each account name

Omar M

Board Regular
Joined
Jan 11, 2024
Messages
66
Office Version
  1. 2019
Platform
  1. Windows
Hello
in RESULT sheet there is no any data, but what I want making report based on sheet1
it should populate accounts names in column B by brings from row1 from column G to last column( every time add new account name so will insert new columns)
as to column C,D for DEBIT,CREDIT will merge for each account name in SHEET1 and the BALANCE column will subtract DEBIT from CREDIT.
I would macro to deal about 7000 rows for SHEET1 when brings data to make macro really fast when brings data.


ACCOUNTS DAILY.xlsm
ABCDEFGHIJKLMNOPQRSTUVWX
1DATECONSTRAIN NODESCRIPTIONBALANCING CASETOTALBANKSAFEPURCHASESELLINGCAPITALPURCHASE RETURNINGSELLING RETURNINGRECEIVABLECREDITOR
2DEBITCREDITDEBITCREDITDEBITCREDITDEBITCREDITDEBITCREDITDEBITCREDITDEBITCREDITDEBITCREDITDEBITCREDITDEBITCREDIT
311/08/20241DEPOSIT CAPITALBALANCED2,000.002,000.002,000.002,000.00
411/08/20242BUYING GOODSBALANCED3,500.003,500.001,500.002,000.003,500.00
511/08/20243SELLING GOODSNOT BALANCED10,000.0015,000.0010,000.0015,000.00
611/08/20244SELLING GOODSBALANCED3,000.003,000.003,000.003,000.00
711/08/20245INCREASE CAPITALBALANCED15,000.0015,000.0015,000.0015000
812/08/20246DECREASE CAPITALBALANCED3,000.003,000.003,000.003,000.00
sheet1



should be like this
ACCOUNTS DAILY.xlsm
ABCDE
1ITEMDEBITDEBITCREDITBALANCE
21BANK10,000.001,500.008,500.00
32SAFE20,000.005,000.0015,000.00
43PURCHASE3,500.000.003,500.00
54SELLING0.0018,000.00-18,000.00
65CAPITAL3,000.0017,000.00-14,000.00
76PURCHASE RETURNING0.000.000.00
87SELLING RETURNING0.000.000.00
98RECEIVABLE0.000.000.00
109CREDITOR0.000.000.00
RESULT
Cell Formulas
RangeFormula
E2:E10E2=C2-D2

I hope finding assistance as DanteAmore did it in earlier .
 
change the error to this line
VBA Code:
arrResult(itemResult, 1) = itemResult
 
Upvote 0

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Please provide a copy of the workbook as previously requested.

please share a copy of your workbook via a sharing platform such as dropbox, google drive etc and make sure the workbook (if you've trimmed it down) still has the issue and that it is made available to anyone with the link.
 
Upvote 0
I would never have guessed that without seeing the file.
Based on your original data, I am expecting a Unique Transaction Type in row 1 with a Debit and Credit column associated with it in row 2.
What is the code supposed to do with all the columns from Y to CG ?

1724157743038.png
 
Upvote 0
OMG!:eek::eek:
sorry for this is error !🙏🙏🙏
shouldn't repeat the same account name, should be different account name.
ok the code works greatly .:)
may I ask you for new requirement please?
Can you modify code by ignoring accounts names contains empty cells or zero for columns DEBIT,CREDIT from showing in RESULT sheet, please?
 
Upvote 0
Ok see how you go with this:
I have modified it so, if you have repeating Transaction types is should consolidate them and added an additional loop that will filter out from the output if both Debit and Credit are 0


Rich (BB code):
Sub ReformatData()
    Dim wsSrc As Worksheet, wsResult As Worksheet
    Dim rngSrc As Range, arrSrc As Variant
    Dim arrResult As Variant, itemResult As Long
    Dim rngResult As Range
    Dim lrResult As Long
    Dim i As Long, j As Long
    
    Set wsSrc = Worksheets("Sheet1")
    Set rngSrc = wsSrc.Range("A1").CurrentRegion
    arrSrc = rngSrc.Value
    
    Set wsResult = Worksheets("RESULT")
    Set rngResult = wsResult.Range("A2").CurrentRegion
    rngResult.Offset(1).ClearContents
    
    Dim dictSrc As Object, dictKey As String
    
    Set dictSrc = CreateObject("Scripting.dictionary")
    dictSrc.CompareMode = vbTextCompare
    
    ' Load details range into Dictionary
    For j = Columns("G").Column To UBound(arrSrc, 2)
        If arrSrc(1, j) <> "" Then
            dictKey = arrSrc(1, j)
            If Not dictSrc.exists(dictKey) Then
                itemResult = itemResult + 1
                dictSrc(dictKey) = itemResult
                arrSrc(1, j + 1) = arrSrc(1, j)
            End If
        Else
            arrSrc(1, j) = arrSrc(1, j - 1)
        End If
    Next j
    
    ReDim arrResult(1 To dictSrc.Count, 1 To 4)
    
      For i = 3 To UBound(arrSrc)
        For j = Columns("G").Column To UBound(arrSrc, 2)
        
        If UCase(arrSrc(2, j)) = "DEBIT" Or UCase(arrSrc(2, j)) = "CREDIT" Then
            itemResult = dictSrc(arrSrc(1, j))
            arrResult(itemResult, 1) = itemResult
            arrResult(itemResult, 2) = arrSrc(1, j)
            
            If UCase(arrSrc(2, j)) = "DEBIT" Then
                arrResult(itemResult, 3) = arrResult(itemResult, 3) + arrSrc(i, j)
            Else
                 arrResult(itemResult, 4) = arrResult(itemResult, 4) + arrSrc(i, j)
            End If
        End If
        Next j
    Next i
    
    Dim arrResultFiltered As Variant, irow As Long
    ReDim arrResultFiltered(1 To UBound(arrResult), 1 To UBound(arrResult, 2))
    
    For i = 1 To UBound(arrResult)
        If arrResult(i, 3) <> 0 Or arrResult(i, 4) <> 0 Then
            irow = irow + 1
            For j = 1 To UBound(arrResult, 2)
                arrResultFiltered(irow, j) = arrResult(i, j)
            Next j
        End If
    Next i
    
    rngResult.Offset(1).Resize(irow, UBound(arrResultFiltered, 2)).Value = arrResultFiltered
    rngResult.Offset(1, 4).Resize(irow, 1).FormulaR1C1 = "=RC[-2]-RC[-1]"

End Sub
 
Upvote 0
Solution
thanks Alex again
but still shows accounts names don't contain value for debit,credit !
 
Upvote 0
We are in different timezones. If you can share the workbook that has the issue with the code it's using I can have a look on the morning.
 
Upvote 0
based on my attachment works perfectly.(y)
many thanks Alex.;)
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,148
Members
453,021
Latest member
Justyna P

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