delete entire row through Macro buttong and VB code

anis_fuelindia

Board Regular
Joined
Aug 8, 2007
Messages
231
Hi All
How can we delete entire row using VB Code.

say example i want to delete a row having name 'Anis' by clicking on a buttton

is this possible?

please help

Thanks

Anis
 
Hi Anis

Sorry for the delay.

I've deleted the use of the "Me" keyword, and used the sheet name as a direct reference......

Code:
Sub CommandButton1_Click()
Private Sub CommandButton1_Click()
Dim nme As String
Dim cll As Range, rng As Range
Dim rcrd As Integer
Set rng = Sheets("Project List").Range("A4:A20") '// "Project List" is the sheet name
rcrd = 0


nme = InputBox("Please type the name of person who's records you wish to delete", "Record delete facility!")
    If nme = "" Then Exit Sub
    
    If MsgBox("You have chosen to delete " & nme & "'s records from the database!" & Chr(10) & "Is this correct?", 52, "DELETING RECORDS!!") = vbNo Then MsgBox "Nothing has been deleted.": Exit Sub

For Each cll In rng
    If cll.Value = nme Then
        Sheets("Project List").Rows(cll.Row).EntireRow.Delete
        rcrd = rcrd + 1
    End If
Next

    If rcrd > 0 Then
        MsgBox rcrd & " of " & nme & "'s records have been deleted!"
    Else
        MsgBox "There were no records matching that name." & Chr(10) & "No records have been deleted."
    End If

End Sub
 
Upvote 0

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

Forum statistics

Threads
1,215,014
Messages
6,122,697
Members
449,092
Latest member
snoom82

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