Deleting a row from a table with a condition

sofas

Active Member
Joined
Sep 11, 2022
Messages
468
Office Version
  1. 2019
Platform
  1. Windows
Screenshot 2022-10-27 001458.png






Hello, I want a code that enables me to search for a specific value in a column and when it is present, the row is deleted from the first table without affecting the second because it contains formulas that should not be deleted

The search condition is in cell sheet2.range("a7")
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Give this a go

VBA Code:
Sub deleteTableRowWithCondition()
    Dim ws As Worksheet: Set ws = ThisWorkbook.Worksheets("Sheet1")
    Dim findValue As String, lr As Long
 
    findValue = Sheet2.Range("A7").Value
 
    With ws.ListObjects("Table24").DataBodyRange ' this is the table you want to delete from... make sure the name is correct (Replace the table name---"Table24")
        lr = .Cells(.Rows.Count, 1).Row
        For i = lr To 1 Step -1
            If .Cells(i, 4) = findValue Then
                .Rows(i).Delete
            End If
        Next i
    End With
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,649
Messages
6,120,733
Members
448,987
Latest member
marion_davis

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