I have the following set data in Sheet1 and start from row 4 column A where the header in row 3:
No Date Code Name Remarks D e b i t Cr e d i t
1 4/30/2015 004/AB/01/04/15 Anna YES 40239.66 0.00
2 2/16/2015 028/AA/01/02/15 Andy NO 0.00 2205.49
3 1/31/2015 021/DR/04/01/15 Jim YES 167.60 0.00
4 7/14/2015 083/RF/01/07/15 Anna YES 3822.60 0.00
5 8/6/2015 030/AB/01/08/15 Anna NO 0.00 11267.96
6 1/15/2015 020/TY/01/01/15 Barry 0.00 5237.84
7 7/14/2015 024/HU/01/07/15 Anna NO 0.00 3822.60
8 1/31/2015 039/JK/01/01/15 YES 0.00 1780.84
9 1/27/2015 007/ER/01/01/15 Jim NO 5237.84 0.00
10 4/29/2015 077/FX/01/04/15 Barry NO 0.00 40239.66
11 1/3/2015 001/OX/10/01/15 Andy NO 33074.03 0.00
12 8/10/2015 001/PR/01/08/15 Nicholas 11267.96 0.00
13 10/31/2015 007/TX/09/10/15 Jim 1780.84 0.00
14 2/28/2015 071/QR/01/02/15 Andy YES 2205.49 0.00
15 1/7/2015 007/OM/02/01/15 Nicholas 8873.25 0.00
And I need to arrange the data above in the same sheet based on the value of debit and credit in no particular order as long as the values of debit and credit: x and y are followed by the values of debit and credit: y and x (preferably x > y) where the unmatched data will be put in the bottom of arranged table. For example something like this :
No Date Code Name Remarks D e b i t Cr e d i t
14 2/28/2015 071/QR/01/02/15 Andy YES 2205.49 0.00
2 2/16/2015 028/AA/01/02/15 Andy NO 0.00 2205.49
4 7/14/2015 083/RF/01/07/15 Anna YES 3822.60 0.00
7 7/14/2015 024/HU/01/07/15 Anna NO 0.00 3822.60
12 8/10/2015 001/PR/01/08/15 Nicholas 11267.96 0.00
5 8/6/2015 030/AB/01/08/15 Anna NO 0.00 11267.96
9 1/27/2015 007/ER/01/01/15 Jim NO 5237.84 0.00
6 1/15/2015 020/TY/01/01/15 Barry 0.00 5237.84
13 10/31/2015 007/TX/09/10/15 Jim 1780.84 0.00
8 1/31/2015 039/JK/01/01/15 YES 0.00 1780.84
1 4/30/2015 004/AB/01/04/15 Anna YES 40239.66 0.00
10 4/29/2015 077/FX/01/04/15 Barry NO 0.00 40239.66
11 1/3/2015 001/OX/10/01/15 Andy NO 33074.03 0.00
15 1/7/2015 007/OM/02/01/15 Nicholas 8873.25 0.00
3 1/31/2015 021/DR/04/01/15 Jim YES 167.60 0.00
Honestly, I couldn't come up with the right code to do this and it's really driving me crazy. This is one of my failed attempts, I've tried something like this
Sub MatchingDebitAndCredit()
Dim i As Long, j As Long, Last_Row As Long
Last_Row = Cells(Rows.Count, "F").End(xlUp).Row
For i = 4 To Last_Row
For j = 4 To Last_Row
If Cells(i, "F").Value = Cells(j, "G").Value And Cells(i, "G").Value = Cells(j, "F").Value Then
Rows(i).EntireRow.Copy Destination:=Worksheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1)
Rows(j).EntireRow.Copy Destination:=Worksheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1)
Exit For
End If
Next j
Next i
End Sub
I copied the matched data in Sheet2 since I was not able to do it the same sheet but it was failed, nothing returned in Sheet2 after the program completed. I intend to do this using arrays and the Find function since the size of data set is very large but how come I could do that if using worksheet can't? Could someone here help me out, please?