Doug Mutzig
Board Regular
- Joined
- Jan 1, 2019
- Messages
- 57
- Office Version
- 365
- Platform
- Windows
Good morning all!
I have a table (T_Staff) with 20 columns (the first 5 are hidden). The 15th column is titled Active and has data validation to allow either Yes or No meaning either the staff is active or is not active. I would like to have a button that when clicked will delete the table rows that have a No in the Active column. I did some digging and found the post and code: https://www.mrexcel.com/forum/excel...ete-row-table.html?highlight=delete+table+row
Original code by DanteAmor :
I have modified the code for my table with the following:
however I am hitting an error on the line
My table headers are on row 11 so I wanted it to start at row 12. Does anyone have an idea of what I have done wrong on this?
Thank you very much for your help and guidance!
Doug
I have a table (T_Staff) with 20 columns (the first 5 are hidden). The 15th column is titled Active and has data validation to allow either Yes or No meaning either the staff is active or is not active. I would like to have a button that when clicked will delete the table rows that have a No in the Active column. I did some digging and found the post and code: https://www.mrexcel.com/forum/excel...ete-row-table.html?highlight=delete+table+row
Original code by DanteAmor :
Code:
[COLOR=#333333]Sub Macro1()[/COLOR] Application.ScreenUpdating = False
Set h = Sheets("unsurprisingly")
If h.AutoFilterMode Then h.AutoFilterMode = False
u = h.Range("K" & Rows.Count).End(xlUp).Row
h.Range("A6:K" & u).AutoFilter Field:=11, Criteria1:="Closed"
Rows("7:" & u).Delete Shift:=xlUp
If h.AutoFilterMode Then h.AutoFilterMode = False
Application.ScreenUpdating = True [COLOR=#333333]End Sub[/COLOR]
I have modified the code for my table with the following:
Code:
Sub StaffRemoveInactive()
Application.ScreenUpdating = False
Set h = Sheets("Staff")
If h.AutoFilterMode Then h.AutoFilterMode = False
u = h.Range("P" & Rows.Count).End(xlUp).Row
h.Range("C12:P" & u).AutoFilter Field:=15, Criteria1:="No"
Rows("12:" & u).Delete Shift:=xlUp
If h.AutoFilterMode Then h.AutoFilterMode = False
Application.ScreenUpdating = True
End Sub
Code:
Rows("12:" & u).Delete Shift:=xlUp
My table headers are on row 11 so I wanted it to start at row 12. Does anyone have an idea of what I have done wrong on this?
Thank you very much for your help and guidance!
Doug