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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
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,635
Messages
6,125,943
Members
449,275
Latest member
jacob_mcbride

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