Help to check balance account number

sbv1986

Board Regular
Joined
Nov 2, 2017
Messages
87
Hi all
I have file data.xlsm with 03 sheets("result","balance01","balance02")
Now I want macro VBA to check value each account number in row i sheet(balance01).column(B,C) with the same account number in row j sheets(balance02).column(F,G)
If the same account but value(Bi) <> value (Fj) or value(Ci) <> value (Gj) => copy row have diffrience value to sheets(result)
Please help me to do this

sheets(balance01) like this:
ABCDEFGH
1Acc numberDebitCreditIncreaseDecreseDebitCredit
2101011000100
3101022000200
4101033000300
5101043000300
6

<tbody>
</tbody>












sheets(balance02) like this:
AVCDEFGH
1Acc numberDebitCreditIncreaseDecreseDebitCredit
2101011000101
3101022000200
4101033000300
5101043001300
6
7...

<tbody>
</tbody>













sheets(result) like this:
ABCDEFGH
1Acc numberDebit balance01Creadit balance01Debit balance 02Credit balance02
21010110001001000101
31010430003003001300
4

<tbody>
</tbody>
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Try:
Code:
Sub CompareCols()
    Application.ScreenUpdating = False
    Dim Val As String, ws1 As Worksheet, ws2 As Worksheet, desWS As Worksheet
    Set desWS = Sheets("result")
    Set ws1 = Sheets("balance01")
    Set ws2 = Sheets("balance02")
    Dim i As Long, v1 As Variant, v2 As Variant
    v1 = ws1.Range("A2", ws1.Range("A" & Rows.Count).End(xlUp)).Resize(, 3).Value
    v2 = ws2.Range("A2", ws2.Range("A" & Rows.Count).End(xlUp)).Resize(, 7).Value
    Application.ScreenUpdating = False
    With CreateObject("Scripting.Dictionary")
        For i = 1 To UBound(v1, 1)
            Val = v1(i, 1) & "|" & v1(i, 2) & "|" & v1(i, 3)
            If Not .Exists(Val) Then
                .Add Val, Nothing
            End If
        Next i
        For i = 1 To UBound(v2, 1)
            Val = v2(i, 1) & "|" & v2(i, 6) & "|" & v2(i, 7)
            If Not .Exists(Val) Then
                desWS.Cells(desWS.Rows.Count, "A").End(xlUp).Offset(1, 0).Resize(, 3) = Array(v1(i, 1), v1(i, 2), v1(i, 3))
                desWS.Cells(desWS.Rows.Count, "D").End(xlUp).Offset(1, 0).Resize(, 2) = Array(v2(i, 6), v2(i, 7))
            End If
        Next i
    End With
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Thanks mumps, code work well. I Have a small question is:
How to change code if I copy data balance 02 to the same sheet?. This mean balance01 from column(A:G) an balance02 fromm column(I:0)
sheet(balance01) look like:


ABCDEFGHIJKLMNO
1AccDebCreIncDecDebCreAccDebCreIncDecDebCre
2
3
4
5
6
7
8
9

<tbody>
</tbody>
 
Upvote 0
Try:
Code:
Sub CompareCols()
    Application.ScreenUpdating = False
    Dim Val As String, desWS As Worksheet, i As Long, v1 As Variant, v2 As Variant
    Set desWS = Sheets("result")
    v1 = Range("A2", Range("A" & Rows.Count).End(xlUp)).Resize(, 3).Value
    v2 = Range("I2", Range("I" & Rows.Count).End(xlUp)).Resize(, 7).Value
    With CreateObject("Scripting.Dictionary")
        For i = 1 To UBound(v1, 1)
            Val = v1(i, 1) & "|" & v1(i, 2) & "|" & v1(i, 3)
            If Not .Exists(Val) Then
                .Add Val, Nothing
            End If
        Next i
        For i = 1 To UBound(v2, 1)
            Val = v2(i, 1) & "|" & v2(i, 6) & "|" & v2(i, 7)
            If Not .Exists(Val) Then
                desWS.Cells(desWS.Rows.Count, "A").End(xlUp).Offset(1, 0).Resize(, 3) = Array(v1(i, 1), v1(i, 2), v1(i, 3))
                desWS.Cells(desWS.Rows.Count, "D").End(xlUp).Offset(1, 0).Resize(, 2) = Array(v2(i, 6), v2(i, 7))
            End If
        Next i
    End With
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,592
Members
449,089
Latest member
Motoracer88

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