VBA to Delete/Remove Table Row Dependent on 1st Column of Table Data

redneck9407

New Member
Joined
Oct 7, 2021
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hello,

I use an excel workbook at work to simplify some of our routine task. This one in particular is used when a project becomes active and material for the project is being approved/released for order. I currently have the 1st column in the Table set as an IF/OR statement because of some misc and shipping fields our software spits out when we perform a Pick List export. Right now the IF statement will place the "Delete" in the 1st cell of the row as seen below. I would like to create a VBA macro to then delete these table rows based on it saying "Delete". The code must all unprotect and re-protect the sheet as well since we have some staff that likes to delete the wrong items. I believe I can handle the protection items but the deletion of these rows has kicked my butt, any help is kindly appreciated!!

1633615304866.png
1633615328869.png
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

goesr

Well-known Member
Joined
Nov 15, 2013
Messages
678
Hello redneck9407 and welcome to the forum. If I understand your problem you might try something like the code below that looks for the word "Delete" in the first column and then deletes the entire row before moving to the next row. Try this on sample data as macros are not reversible. Hope this helps you get started.

VBA Code:
Sub DeleteRowsWithDelete()
i = 1
While i < 30
Cells(i, 1).Select
    If Cells(i, 1).Value = "Delete" Then
    Cells(i, 1).EntireRow.Delete
    i = i - 1
    
    End If
i = i + 1
Wend
End Sub
 

Forum statistics

Threads
1,147,568
Messages
5,741,874
Members
423,692
Latest member
Bhanu1988

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
Top