Clear contents in table based on certain words in last column

cheesypoofs

New Member
Joined
Mar 7, 2023
Messages
9
Office Version
  1. 365
Platform
  1. Windows
Hello all! I am extremely new to VBA, so my question may be dumb or simple, but I haven't been able to find the answer anywhere... I am trying to make a sales tracker with a table range from A2:G103 including headers. Column G in that table will include a dropdown to select options such as offer sent, scheduled, installed, pending acceptance, cancelled, and so on. I have made a code to clear the full contents of the table, but I also want to create a macro to clear only the rows in the table that contain "installed, scheduled, and cancelled". I have tried fooling around with .Auto filter, but I might be missing something because it ends up deleting my table (save the headers). Any tips would be great!
 

Attachments

  • IMG_20230307_210752.jpg
    IMG_20230307_210752.jpg
    61.6 KB · Views: 11

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Try this:

VBA Code:
Sub DeleteRows()
Dim dRng As Range
With ActiveSheet.ListObjects("Table1")
    .Range.AutoFilter Field:=7, Criteria1:=Array("Cancelled", "Installed", "Scheduled"), Operator:=xlFilterValues
    If WorksheetFunction.Subtotal(2, .DataBodyRange) > 0 Then
        Set dRng = .DataBodyRange.SpecialCells(xlCellTypeVisible)
        .Range.AutoFilter
        dRng.Delete xlUp
    End If
End With
End Sub
 
Upvote 0
Dim dRng As Range With ActiveSheet.ListObjects("Table1") .Range.AutoFilter Field:=7, Criteria1:=Array("Cancelled", "Installed", "Scheduled"), Operator:=xlFilterValues If WorksheetFunction.Subtotal(2, .DataBodyRange) > 0 Then Set dRng = .DataBodyRange.SpecialCells(xlCellTypeVisible) .Range.AutoFilter dRng.Delete xlUp End If End With
That works, but then it ends up deleting cells within the table. I want to keep the table as long as it is for user input without removing those sells all together, thats why I want it to just clear contents while keeping the format of the table
 
Upvote 0

Forum statistics

Threads
1,215,842
Messages
6,127,235
Members
449,372
Latest member
charlottedv

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