Debits and Credits to offset in a column

kjaan

New Member
Joined
Feb 2, 2011
Messages
20
Hi,
I have a large data that I exported in excel that include debit and credit in a column. I would like to find an easier way to pair the debit and credit to offset each other by a formula and easily find the variance. So the column would look something like this.

Column A
250
400
350
-250
410
-400
-350
600
-410
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
so does that mean the credits are in rows 2, 4, 6, 8... while debits are in 3, 5, 7, 9...?


Hi,
I have a large data that I exported in excel that include debit and credit in a column. I would like to find an easier way to pair the debit and credit to offset each other by a formula and easily find the variance. So the column would look something like this.

Column A
250
400
350
-250
410
-400
-350
600
-410
 
Upvote 0
The other columns are irrelevant because I am trying to offset debit and credit to net zero.
 
Upvote 0
Hi kjaan,

Try this where the matched amounts will be shifted to Col. B leaving only the unmatched amount(s) in Col. A:

Code:
Option Explicit
Sub Macro1()

    Dim lngEndRow As Long
    Dim rngMyCell As Range
    Dim rngMatchCell As Range
    
    lngEndRow = Cells(Rows.Count, "A").End(xlUp).Row
    
    Application.ScreenUpdating = False
    
    For Each rngMyCell In Range("A1:A" & lngEndRow)
        If Len(rngMyCell) > 0 Then 'ignore blank cells either by design or that have had their value shifted by the following code
            For Each rngMatchCell In Range("A1:A" & lngEndRow)
                If Val(rngMatchCell) * -1 = Val(rngMyCell) Then
                    rngMyCell.Offset(0, 1).Value = rngMyCell
                    rngMatchCell.Offset(0, 1).Value = rngMatchCell
                    rngMyCell.ClearContents
                    rngMatchCell.ClearContents
                    Exit For
                End If
            Next rngMatchCell
        End If
    Next rngMyCell
    
    Application.ScreenUpdating = True

End Sub

Regards,

Robert
 
Upvote 0
Hi kjaan,

Try this where the matched amounts will be shifted to Col. B leaving only the unmatched amount(s) in Col. A:

Code:
Option Explicit
Sub Macro1()

    Dim lngEndRow As Long
    Dim rngMyCell As Range
    Dim rngMatchCell As Range
    
    lngEndRow = Cells(Rows.Count, "A").End(xlUp).Row
    
    Application.ScreenUpdating = False
    
    For Each rngMyCell In Range("A1:A" & lngEndRow)
        If Len(rngMyCell) > 0 Then 'ignore blank cells either by design or that have had their value shifted by the following code
            For Each rngMatchCell In Range("A1:A" & lngEndRow)
                If Val(rngMatchCell) * -1 = Val(rngMyCell) Then
                    rngMyCell.Offset(0, 1).Value = rngMyCell
                    rngMatchCell.Offset(0, 1).Value = rngMatchCell
                    rngMyCell.ClearContents
                    rngMatchCell.ClearContents
                    Exit For
                End If
            Next rngMatchCell
        End If
    Next rngMyCell
    
    Application.ScreenUpdating = True

End Sub

Regards,

Robert

I can't use vba because my work doesn't have option to use developer add-in.
 
Upvote 0
What is your expected result?
My expected result is that I have to find the offsetting debit and credit in the columns by formula and find the variance balance. Once I narrow down the variance then I can research why variance exists.
 
Upvote 0
Well, the logic here is flawed, because unless you have transaction or GL Ids, if your data is missing one GL entry at some point it will all get messed up.

Otherwise here is the formula:

Your data starts at A1 and ends at A9
In B1 cell use:
=IFERROR(IF(ROWS(B$1:B1)>COUNTA(A:A),"",INDEX(A:A,SMALL(IF(A$1:A$9>0,ROW(A$1:A$9)),ROWS(B$1:B1)))),"")

In C1 cell use:
=IFERROR(IF(ROWS(B$1:B1)>COUNTA(A:A),"",INDEX(A:A,SMALL(IF(A$1:A$9<0,ROW(A$1:A$9)),ROWS(B$1:B1)))),"")

Apply both formulas using CTRL+SHIFT+ENTER, don't just use enter, and then fill down.
 
Upvote 0

Forum statistics

Threads
1,215,111
Messages
6,123,159
Members
449,098
Latest member
Doanvanhieu

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