Delete Table Row based in Cell Value

cefrb

New Member
Joined
Aug 8, 2020
Messages
1
Office Version
  1. 2016
Platform
  1. Windows
I have a table (Table2) that contains properties informations, in the first column (Código do Imóvel) i have a code for the property. I have a cell ("Alterar Registro de Imóveis", F3) with data validation based in the values of the first column from the table. I want to delete the row started with the given code, when the user click two yes through msgboxes.
VBA Code:
If MsgBox("Tem certeza que deseja deletar " & Sheets("Alterar Registro de Imóveis").Range("F3") & "?", vbExclamation + vbYesNo, "Deletar Imóvel") = vbYes Then
        If MsgBox("Após essa confirmação, o registro " & Sheets("Alterar Registro de Imóveis").Range("F3") & " será deletado permanentemente. Deseja continuar?", vbExclamation + vbYesNo, "Deletar Imóvel") = vbYes Then
            Worksheets("Tabela de Imóveis").ListObjects("Table2").ListRows(Application.Match(Sheets("Alterar Registro de Imóveis").Range("F3"), Worksheets("Tabela de Imóveis").ListObjects("Table2").ListRows("Código do Imóvel"), 0), 2).Delete
        End If
    End If
I tried ListRows and Match to find the number from the row.
Someone know how to do this?
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
This is a piece of code I have that should be easily adapted to do what you want.
VBA Code:
Sub del_Row()


    Set ws = Worksheets("Sheet1") 'change sheet1 for your sheet name
    

For Each cL In ws.Range("a:a") 'change for the range you want to search
    If cL.Row <> 1 Then
    If cL.Value = ("Error") Or cL.Value = ("error") Or cL.Value = ("ERROR") Then 'change values to suit what you want to search, add or remove as required.
        cL.Select
        cL.EntireRow.Delete
        ElseIf cL.Value = vbNullString Then
    Exit For
    End If
    End If
    Next
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,918
Members
449,094
Latest member
teemeren

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