PDA

View Full Version : Vlookup to delete entire row on another worksheet



markkeith
09-02-2020, 05:13 AM
Hi All, lets say I have a numeric data on Sheet1 Range A1 to find from Sheet2 Range A1:A40 using Vlookup. When I click the command button, I want to delete that row where data was match or found and display message if nothing found.

I know there must be something more for this code to work but I don't what it is.



Private Sub btnReturn_Click()
Application.VLookup(Activesheet.Range("A1").Value, Sheet2.Range("A1:A40"), 1, False).EntireRow.Delete
End Sub

markkeith
09-02-2020, 05:57 AM
I made a progress from reading post, here's a working code if data was found.



Private Sub btnReturn_Click()
Dim rowDel As String
rowDel = Range("A1")
Set c = Sheet2.Range("A1:A40").Find(rowDel)
Sheet2.Range(c.Address()).EntireRow.Delete
End Sub


All I need now is code to handle error.

JKwan
09-02-2020, 09:51 AM
give this a try


If Not C Is Nothing Then
Sheet2.Range(C.Address()).EntireRow.Delete
End If

markkeith
09-02-2020, 03:09 PM
It works, thank you JKwan.