VBA to remove a row from a table

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,341
Office Version
  1. 365
Platform
  1. Windows
I have a ta Table (Table7) on Sheet "Cats"

I want to to be able to remove/delete one of the Row based on whats in cell C10 on sheet4. C10 on sheet4 is a Listbox based on the table

So if C10 the user selected "Mechanical" the code will find "Mechanical in table7 and delete it.

Hope that makes sense. Thanks for the help and teaching us how to do amazing things!
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Try this:
The following deletes the row from the table, it does not delete the entire row from the sheet.

VBA Code:
Sub DeleteInTable()
  Dim tbl As ListObject
  Dim f As Range
  Dim i As Long
  Set tbl = Sheets("Cats").ListObjects("Table7")
  Set f = tbl.DataBodyRange.Find(Sheets("Sheet4").Range("C10").Value, , xlValues, xlWhole, , , False)
  If Not f Is Nothing Then
    i = tbl.Range.Cells(1).Row
    tbl.ListRows(f.Row - i).Delete
  End If
End Sub
 
Upvote 0
Solution
Im glad to helo you, thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,996
Messages
6,122,636
Members
449,092
Latest member
bsb1122

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