How to remove several ranges in table at the same time

Brutusar

Board Regular
Joined
Nov 23, 2019
Messages
166
Office Version
  1. 365
Platform
  1. Windows
Hi, I have a sheet with thousands or rows showing transport statuses. (See example below) . The start (Sendt) and end status (Delivered) is always the same, but the number of steps between these statuses will wary. The id number (Showing in col D will always be available for all steps in a shipment, and will be unique.

How can I find all shipments that are completed? (has both the Sendt and Delivered status so these can be removed from the list, including all steps between Sendt and Delivered? )

Example.xlsx
ABCD
11245New YorkSendt55468
21245New YorkStep 155468
31245New YorkStep 255468
41245New YorkStep 355468
51245New YorkStep 455468
61245New YorkStep 555468
71245New YorkStep 6 55468
81245New YorkStep 755468
91245New YorkDelivered55468
101354ChicagoSendt6657985
111354ChicagoStep 26657985
121354ChicagoStep 36657985
131354ChicagoStep 46657985
141354ChicagoStep 56657985
151445SeattleSendt5578223
161445SeattleStep 15578223
171445SeattleStep 25578223
181445SeattleStep 35578223
191445SeattleStep 45578223
201445SeattleStep 55578223
211445SeattleStep 6 5578223
221445SeattleStep 75578223
231445SeattleDelivered5578223
245589 DallasSendt997855
255589 DallasStep 1997855
265589 DallasStep 2997855
Sheet1
 
Assuming the transport statuses to be deleted are the only ones that will have "Delivered" in Column C, give this code a try...
VBA Code:
Sub DeleteDeliveredTrensports()
  Dim Cell As Range
  Columns("C").Replace "Delivered", "", xlWhole
  For Each Cell In Columns("C").SpecialCells(xlBlanks).Areas
    Columns("D").Replace Cell.Offset(, 1).Value, "#N/A", xlWhole
  Next
  Columns("D").SpecialCells(xlConstants, xlErrors).EntireRow.Delete
End Sub
Working perfect, thank you very much!
 
Upvote 0

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
What do you mean by "sometimes"?
Sometimes VBA is the answer. But I still have a problem with anything that deletes original data instead of a copy whether it's VBA or a formula. Worth noting that it's impossible using Power Query since it only works on a copy of any data.
 
Upvote 0
Sometimes VBA is the answer. But I still have a problem with anything that deletes original data instead of a copy whether it's VBA or a formula. Worth noting that it's impossible using Power Query since it only works on a copy of any data.
If original data is to be preserved, then just have the code copy the original data to another location first, then run my original posted code (adjusted for the new location including modifying the last line) afterwards. For example...
VBA Code:
Sub DeleteDeliveredTrensports()
  Dim Cell As Range
  Columns("A:D").Copy Range("F1")
  Columns("H").Replace "Delivered", "", xlWhole
  For Each Cell In Columns("H").SpecialCells(xlBlanks).Areas
    Columns("I").Replace Cell.Offset(, 1).Value, "#N/A", xlWhole
  Next
  Intersect(Columns("F:I"), Columns("I").SpecialCells(xlConstants, xlErrors).EntireRow).Delete
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,030
Messages
6,122,762
Members
449,095
Latest member
m_smith_solihull

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