Can Excel execute this complex value recheck with rows being deleted?

Coyotex3

Active Member
Joined
Dec 12, 2021
Messages
496
Office Version
  1. 365
Platform
  1. Windows
1640232867081.png


So, I would like to tell excel to look at the value in row(Where it says Cash Available) in this case "H16" and if the value is less than the value above it "H15" to delete where Range("D") = "Okinawa" and Range("A") = OsaCon, starting by oldest date "Range("E") reexamine to see if value in "H16" is greater than the value in "H15."

Thank you.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
@Coyotex3, Can you please use XL2BB to post your examples? A lot of people are not going to take the time to type in all of the info that you are posting via pics just to try and assist you. If you use the XL2BB add in, others can just copy and paste your info that you provided and then start looking into assisting you.

That being said, can you post a better example, before & after?

I ask because I don't think you want to do what you have said. Maybe you can rephrase what you want to do in addition to showing a better before and after.
 
Upvote 0
@Coyotex3, Can you please use XL2BB to post your examples? A lot of people are not going to take the time to type in all of the info that you are posting via pics just to try and assist you. If you use the XL2BB add in, others can just copy and paste your info that you provided and then start looking into assisting you.

That being said, can you post a better example, before & after?

I ask because I don't think you want to do what you have said. Maybe you can rephrase what you want to do in addition to showing a better before and after.
Hey what is XL2BB ?
 
Upvote 0
Practice(16911).xlsx
ABCDEFGHI
1Exported Report
2usa
3Period:
4As of :
5CodePersonNotesLocationInvoice DateDescriptionInvoice #AmountNotes
6FukConFukuoka ConstructionBridgeFukuoka10/2/202100000000-Construction920,000.00Bridge
7FukConFukuoka ConstructionBridgeFukuoka10/2/202100000000-Construction1820,000.00Bridge
8Account Payables40,000.00
9Cash Availables60,000.00
10
11FukConFukuoka ConstructionBridgeOkinawa9/30/202100000000-Construction1620,000.00Bridge
12OkiConOkinawa ConstructionNew BuildingOkinawa12/5/2021000000000- Construction150,000.00New Building
13OkiConOkinawa ConstructionNew BuildingOkinawa12/6/2021000000000- Construction1050,000.00New Building
14OsaConOsaka ConstructionBeen PaidOkinawa7/1/202100000000-Construction550,000.00WIP
15OsaConOsaka ConstructionBeen PaidOkinawa12/15/202000000000-Construction1460,000.00WIP
16Account Payables230,000.00
17Cash Availables120,000.00
18
19OsaConOsaka ConstructionBeen PaidOsaka8/2/202100000000-Construction350,000.00WIP
20OsaConOsaka ConstructionBeen PaidOsaka8/2/202100000000-Construction1250,000.00WIP
21Account Payables100,000.00
22Cash Availables200,000.00
23
24FukConFukuoka ConstructionBridgeT+8:20okyo10/1/202100000000-Construction820,000.00Bridge
25FukConFukuoka ConstructionBridgeT+8:20okyo10/1/202100000000-Construction1720,000.00Bridge
26Account Payables40,000.00
27Cash Availables40,000.00
28
29OsaConOsaka ConstructionBeen PaidTokyo8/5/202100000000-Construction450,000.00WIP
30OsaConOsaka ConstructionBeen PaidTokyo8/5/202100000000-Construction1350,000.00WIP
31TokConTokyo ConstructionBuilding RenewalTokyo12/4/202100000000-Construction25,000.00Renewal
32TokConTokyo ConstructionBuilding RenewalTokyo12/4/202100000000-Construction115,000.00Renewal
33Account Payables110,000.00
34Cash Availables200,000.00
35
Report1
Cell Formulas
RangeFormula
H8,H26,H21H8=SUM(H6:H7)
H16H16=SUM(H11:H15)
H27H27=SUM(H26)
H33H33=SUM(H29:H32)


Does this work?

I would like to tell excel to look at the value in row(Where it says Cash Available) in this case "H17" and if the value is less than the value above it "H16" to delete where Range("D") = "Okinawa" and Range("A") = OsaCon, starting by oldest date "Range("E") reexamine to see if value in "H17" is greater than the value in "H16."
 
Upvote 0
What do you want the final result to look like?
 
Upvote 0
What do you want the final result to look like?
Hey JohnnyL, thank you for working with me on this once again. For my end result I would like for the code to delete row 16 since it meets the requirements of "Range D = Okinawa" and "Range A = OsaCon" and it is the oldest invoice. After that I want it to reexamine and check if "H17" is greater or equal to "H16" if so then exit sub. If the value in "H17" is less than "H16" delete the next range that meets the parameter etc.

I know this is a bit complicated since I would like for the system to edit the Auto Sum values and ranges.

The end goal is to build onto this in order to get it to look for different keywords in different ranges. Hope this helps clarify things a bit more.
 
Upvote 0
Ok, I tried to ask you for clarification and you didn't give me what I was trying to find out so try the following and see if it does what you want:

VBA Code:
Sub DeleteRowPerTests()
'
    Dim OldestDate          As Date
    Dim PreviousRow         As Long
    Dim LastRowInColumnG    As Long
    Dim OffsetColumn        As Long
    Dim OffsetRow           As Long
    Dim RowToDelete         As Long
    Dim StartRowData        As Long
    Dim cell                As Range
'
    StartRowData = 6
'
    LastRowInColumnG = Range("G" & Rows.Count).End(xlUp).Row                                ' Get last row # used in column G
'
StartOfForEachLoop:
    For Each cell In Range("G" & StartRowData & ":G" & LastRowInColumnG)                    ' Loop through the G column
        OffsetColumn = 0
        OffsetRow = 0
'
        If cell.Value = "Cash Available" And cell.Offset(OffsetRow, OffsetColumn + 1) <> vbNullString And _
            cell.Offset(OffsetRow, OffsetColumn + 1) < cell.Offset(OffsetRow - 1, OffsetColumn + 1) And _
            cell.Offset(OffsetRow - 2, OffsetColumn - 3) = "Okinawa" _
            And cell.Offset(OffsetRow - 2, OffsetColumn - 6) = "OsaCon" Then                '   If all conditions are met then ...
'
            OldestDate = cell.Offset(OffsetRow - 2, OffsetColumn - 2).Value2                '       Save the OldestDate
            RowToDelete = cell.Offset(OffsetRow - 2, OffsetColumn - 2).Row                  '       Save the RowToDelete for the OldestDate
'
            For PreviousRow = 3 To RowToDelete - StartRowData
                If cell.Offset(OffsetRow - PreviousRow, OffsetColumn - 3) = "Okinawa" And _
                    cell.Offset(OffsetRow - PreviousRow, OffsetColumn - 6) = "OsaCon" Then  '           If both other conditions are met then ...
                        If cell.Offset(OffsetRow - PreviousRow, OffsetColumn - 2).Value2 < OldestDate Then  '               If older date found then ...
                            OldestDate = cell.Offset(OffsetRow - PreviousRow, OffsetColumn - 2).Value2  '                       Save the Date as the OldestDate
                            RowToDelete = cell.Offset(OffsetRow - PreviousRow, OffsetColumn - 2).Row    '                   Save the RowToDelete for the OldestDate
                        End If
                Else
                    Exit For                                                                '               Exit for loop
                End If
            Next
'
            Rows(RowToDelete).EntireRow.Delete                                              '       Delete the row with the earliest date that matches all criteria
'
            GoTo StartOfForEachLoop                                                         '       Go back to beginning of loop and check again
        End If
    Next
End Sub
 
Upvote 0
Ok, I tried to ask you for clarification and you didn't give me what I was trying to find out so try the following and see if it does what you want:

VBA Code:
Sub DeleteRowPerTests()
'
    Dim OldestDate          As Date
    Dim PreviousRow         As Long
    Dim LastRowInColumnG    As Long
    Dim OffsetColumn        As Long
    Dim OffsetRow           As Long
    Dim RowToDelete         As Long
    Dim StartRowData        As Long
    Dim cell                As Range
'
    StartRowData = 6
'
    LastRowInColumnG = Range("G" & Rows.Count).End(xlUp).Row                                ' Get last row # used in column G
'
StartOfForEachLoop:
    For Each cell In Range("G" & StartRowData & ":G" & LastRowInColumnG)                    ' Loop through the G column
        OffsetColumn = 0
        OffsetRow = 0
'
        If cell.Value = "Cash Available" And cell.Offset(OffsetRow, OffsetColumn + 1) <> vbNullString And _
            cell.Offset(OffsetRow, OffsetColumn + 1) < cell.Offset(OffsetRow - 1, OffsetColumn + 1) And _
            cell.Offset(OffsetRow - 2, OffsetColumn - 3) = "Okinawa" _
            And cell.Offset(OffsetRow - 2, OffsetColumn - 6) = "OsaCon" Then                '   If all conditions are met then ...
'
            OldestDate = cell.Offset(OffsetRow - 2, OffsetColumn - 2).Value2                '       Save the OldestDate
            RowToDelete = cell.Offset(OffsetRow - 2, OffsetColumn - 2).Row                  '       Save the RowToDelete for the OldestDate
'
            For PreviousRow = 3 To RowToDelete - StartRowData
                If cell.Offset(OffsetRow - PreviousRow, OffsetColumn - 3) = "Okinawa" And _
                    cell.Offset(OffsetRow - PreviousRow, OffsetColumn - 6) = "OsaCon" Then  '           If both other conditions are met then ...
                        If cell.Offset(OffsetRow - PreviousRow, OffsetColumn - 2).Value2 < OldestDate Then  '               If older date found then ...
                            OldestDate = cell.Offset(OffsetRow - PreviousRow, OffsetColumn - 2).Value2  '                       Save the Date as the OldestDate
                            RowToDelete = cell.Offset(OffsetRow - PreviousRow, OffsetColumn - 2).Row    '                   Save the RowToDelete for the OldestDate
                        End If
                Else
                    Exit For                                                                '               Exit for loop
                End If
            Next
'
            Rows(RowToDelete).EntireRow.Delete                                              '       Delete the row with the earliest date that matches all criteria
'
            GoTo StartOfForEachLoop                                                         '       Go back to beginning of loop and check again
        End If
    Next
End Sub
Sorry that I did not answer the question properly. Did you want me to upload the xl2bb file instead?


Not sure what is going on with my sheet, but this macro is not doing anything. It is going from the first If to the end of the sub.
 
Upvote 0
Sorry, didn't realize you changed the name:

VBA Code:
Sub DeleteRowPerTests()
'
    Dim OldestDate          As Date
    Dim PreviousRow         As Long
    Dim LastRowInColumnG    As Long
    Dim OffsetColumn        As Long
    Dim OffsetRow           As Long
    Dim RowToDelete         As Long
    Dim StartRowData        As Long
    Dim cell                As Range
'
    StartRowData = 6
'
    LastRowInColumnG = Range("G" & Rows.Count).End(xlUp).Row                                ' Get last row # used in column G
'
StartOfForEachLoop:
    For Each cell In Range("G" & StartRowData & ":G" & LastRowInColumnG)                    ' Loop through the G column
        OffsetColumn = 0
        OffsetRow = 0
'
        If cell.Value = "Cash Availables" And cell.Offset(OffsetRow, OffsetColumn + 1) <> vbNullString And _
            cell.Offset(OffsetRow, OffsetColumn + 1) < cell.Offset(OffsetRow - 1, OffsetColumn + 1) And _
            cell.Offset(OffsetRow - 2, OffsetColumn - 3) = "Okinawa" _
            And cell.Offset(OffsetRow - 2, OffsetColumn - 6) = "OsaCon" Then                '   If all conditions are met then ...
'
            OldestDate = cell.Offset(OffsetRow - 2, OffsetColumn - 2).Value2                '       Save the OldestDate
            RowToDelete = cell.Offset(OffsetRow - 2, OffsetColumn - 2).Row                  '       Save the RowToDelete for the OldestDate
'
            For PreviousRow = 3 To RowToDelete - StartRowData
                If cell.Offset(OffsetRow - PreviousRow, OffsetColumn - 3) = "Okinawa" And _
                    cell.Offset(OffsetRow - PreviousRow, OffsetColumn - 6) = "OsaCon" Then  '           If both other conditions are met then ...
                        If cell.Offset(OffsetRow - PreviousRow, OffsetColumn - 2).Value2 < OldestDate Then  '               If older date found then ...
                            OldestDate = cell.Offset(OffsetRow - PreviousRow, OffsetColumn - 2).Value2  '                       Save the Date as the OldestDate
                            RowToDelete = cell.Offset(OffsetRow - PreviousRow, OffsetColumn - 2).Row    '                   Save the RowToDelete for the OldestDate
                        End If
                Else
                    Exit For                                                                '               Exit for loop
                End If
            Next
'
            Rows(RowToDelete).EntireRow.Delete                                              '       Delete the row with the earliest date that matches all criteria
'
            GoTo StartOfForEachLoop                                                         '       Go back to beginning of loop and check again
        End If
    Next
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,059
Messages
6,122,916
Members
449,093
Latest member
dbomb1414

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