Hi
in earlier time I got help by @Alex Blakenburg in this thread
exclude zero value of the data in last row for each name
I'm not sure how adjusting this code , or alternative.
I want to copy the data for the last row for each duplicate name in column C , and ignore all of the rest of data for the same name , and if the last row contains a zero for column G for a specific name also should ignore it .
I put what I want in second sheet.
result
could be data about 6000 rows .
I hope Alex see my thread or anybody could help.
thanks
in earlier time I got help by @Alex Blakenburg in this thread
exclude zero value of the data in last row for each name
I'm not sure how adjusting this code , or alternative.
VBA Code:
Sub KeepOpenTransactions()
Dim shtSrc As Worksheet, shtDest As Worksheet
Dim srcRowLast As Long
Dim srcRng As Range, destRng As Range
Dim srcArr As Variant, destArr As Variant
Dim i As Long, iKeepFlag As Long, totalKeep As Long, j As Long, k As Long
Set shtSrc = Worksheets("filter")
Set shtDest = Worksheets("CLEAN")
With shtSrc
srcRowLast = .Range("A" & Rows.Count).End(xlUp).Row
Set srcRng = .Range("A1:G" & srcRowLast)
srcArr = srcRng.Value2
ReDim Preserve srcArr(1 To UBound(srcArr), 1 To UBound(srcArr, 2) + 1)
End With
Set destRng = shtDest.Range("A2")
Dim dictSrc As Object, dictKey As String
Set dictSrc = CreateObject("Scripting.dictionary")
' Load Client names into Dictionary and get highest row for Client with zero balance
For i = 2 To UBound(srcArr)
dictKey = srcArr(i, 3)
If Not dictSrc.exists(dictKey) Then
dictSrc(dictKey) = 0
End If
If srcArr(i, 7) = 0 Then
dictSrc(dictKey) = i
End If
Next i
' Flag Source Array lines to keep
srcArr(1, 8) = iKeepFlag ' Keep Heading
totalKeep = 1
iKeepFlag = 1
For i = 2 To srcRowLast
dictKey = srcArr(i, 3)
If i > dictSrc(dictKey) Then
srcArr(i, 8) = iKeepFlag
totalKeep = totalKeep + 1
End If
Next i
' Move lines to keep to output array
ReDim destArr(1 To totalKeep + 1, 1 To UBound(srcArr, 2) - 1)
For i = 1 To UBound(srcArr)
If srcArr(i, 8) = 1 Then
j = j + 1
For k = 1 To UBound(destArr, 2)
destArr(j, k) = srcArr(i, k)
Next k
End If
Next i
destRng.CurrentRegion.ClearContents
Set destRng = destRng.Resize(j, UBound(destArr, 2))
destRng.Value2 = destArr
srcRng.Rows(2).Copy
destRng.PasteSpecial Paste:=xlPasteFormats
srcRng.Rows(1).Copy Destination:=destRng.Rows(1)
srcRng.Rows(1).Copy Destination:=destRng.Offset(-1).Rows(1)
destRng.Columns.AutoFit
shtDest.Sort.SortFields.Clear
destRng.Sort Key1:=destRng.Cells(1, 3), Order1:=xlAscending, Header:=xlYes
End Sub
I want to copy the data for the last row for each duplicate name in column C , and ignore all of the rest of data for the same name , and if the last row contains a zero for column G for a specific name also should ignore it .
I put what I want in second sheet.
box (1).xlsm | |||||||||
---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | |||
1 | DATE | INVOICE NO | CLIENT NO | DESCRIBE | DEBIT | CREDIT | BALANCE | ||
2 | 01/01/2022 | - | ABDEND1 | OPENNING | 20,000.00 | 0.00 | 20,000.00 | ||
3 | 04/01/2022 | PA-B3 | ABDEND1 | PA | 20,000.00 | 0.00 | 40,000.00 | ||
4 | 05/01/2022 | SA-B35 | ABDEND1 | SA | 0.00 | 1,000.00 | 39,000.00 | ||
5 | 06/01/2022 | SA-B36 | ABDEND1 | SA | 1,000.00 | 39,000.00 | 1,000.00 | ||
6 | 07/01/2022 | PA-B3 | ABDEND1 | PA | 1,000.00 | 100.00 | 1,900.00 | ||
7 | 02/01/2022 | PA-B36 | ABDEND2 | PA | 1,000.00 | 0.00 | 1,000.00 | ||
8 | 07/01/2022 | PA-B37 | ABDEND2 | PA | 1,000.00 | 0.00 | 2,000.00 | ||
9 | 08/01/2022 | SA-B37 | ABDEND2 | PA | 500.00 | 2,000.00 | 500.00 | ||
10 | 09/01/2022 | PA-B38 | ABDEND2 | PA | 1,000.00 | 0.00 | 1,500.00 | ||
11 | 10/01/2022 | PA-B39 | ABDEND2 | PA | 1,500.00 | 0.00 | 3,000.00 | ||
12 | 11/01/2022 | PA-B40 | ABDEND3 | OPENNING | 0.00 | 200.00 | -200.00 | ||
13 | 12/01/2022 | PA-B41 | ABDEND3 | PA | 5,000.00 | 0.00 | 4,800.00 | ||
14 | 13/01/2022 | PA-B42 | ABDEND3 | PA | 5,000.00 | 0.00 | 9,800.00 | ||
15 | 14/01/2022 | PA-B43 | ABDEND3 | PA | 5,000.00 | 0.00 | 14,800.00 | ||
16 | 15/01/2022 | PA-B44 | ABDEND3 | PA | 2,000.00 | 0.00 | 16,800.00 | ||
17 | 16/01/2022 | PA-B45 | ABDEND3 | PA | 1,000.00 | 100.00 | 17,700.00 | ||
18 | 17/01/2022 | SA-B38 | ABDEND3 | SA | 1,000.00 | 17,700.00 | 1,000.00 | ||
19 | 19/01/2022 | PA-B47 | ABDEND3 | PA | 2,000.00 | 500.00 | 2,500.00 | ||
20 | 20/01/2022 | PA-B48 | ABDEND3 | PA | 2,000.00 | 1,000.00 | 3,500.00 | ||
21 | 18/01/2022 | PA-B46 | ABDEND4 | PA | 1,000.00 | 100.00 | 900.00 | ||
22 | 21/01/2022 | PA-B49 | ABDEND4 | PA | 900.00 | 900.00 | 900.00 | ||
23 | 22/01/2022 | PA-B50 | ABDEND5 | PA | 200.00 | 0.00 | 200.00 | ||
24 | 26/01/2022 | PA-B53 | ABDEND5 | PA | 200.00 | 100.00 | 300.00 | ||
25 | 28/01/2022 | PA-B54 | ABDEND5 | PA | 200.00 | 300.00 | 200.00 | ||
26 | 23/01/2022 | PA-B51 | ABDEND6 | PA | 1,200.00 | 200.00 | 1,000.00 | ||
27 | 25/01/2022 | SA-B39 | ABDEND6 | SA | 0.00 | 400.00 | 600.00 | ||
28 | 27/01/2022 | SA-B40 | ABDEND6 | SA | 0.00 | 600.00 | 0.00 | ||
FILTER |
Cell Formulas | ||
---|---|---|
Range | Formula | |
G2,G26,G23,G21,G12,G7 | G2 | =E2-F2 |
G27:G28,G24:G25,G22,G13:G20,G8:G11,G3:G6 | G3 | =G2+E3-F3 |
result
box(1).xlsm | |||||||||
---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | |||
1 | DATE | INVOICE NO | CLIENT NO | DESCRIBE | DEBIT | CREDIT | BALANCE | ||
2 | 07/01/2022 | PA-B3 | ABDEND1 | PA | 1,000.00 | 100.00 | 1,900.00 | ||
3 | 10/01/2022 | PA-B39 | ABDEND2 | PA | 1,500.00 | 0.00 | 3,000.00 | ||
4 | 20/01/2022 | PA-B48 | ABDEND3 | PA | 2,000.00 | 1,000.00 | 3,500.00 | ||
5 | 21/01/2022 | PA-B49 | ABDEND4 | PA | 900.00 | 900.00 | 900.00 | ||
6 | 28/01/2022 | PA-B54 | ABDEND5 | PA | 200.00 | 300.00 | 200.00 | ||
CLEAN |
could be data about 6000 rows .
I hope Alex see my thread or anybody could help.
thanks
Last edited by a moderator: