Hi,
I have been searching for a way to delete a row based on the value of a particular column. I keep finding "functional code" online, but they all result in automation errors for me.
Basically, what I want to accomplish is this: When the "delete activity" button is clicked, excel will search column B in the Activities Inventory for a cell that matches that value. If a match is found, that row will be deleted.
I have the following code written, but it is giving me an automation error. Can somebody please help me out with this?
I have been searching for a way to delete a row based on the value of a particular column. I keep finding "functional code" online, but they all result in automation errors for me.
Basically, what I want to accomplish is this: When the "delete activity" button is clicked, excel will search column B in the Activities Inventory for a cell that matches that value. If a match is found, that row will be deleted.
I have the following code written, but it is giving me an automation error. Can somebody please help me out with this?
Code:
Private Sub btnDeleteActivity_Click()
Application.ScreenUpdating = False
ActiveSheet.Select
ActivityName = ActiveSheet.Name
Application.DisplayAlerts = False
Message = "Are you sure you want to delete the current Activity Worksheet named: " & ActivityName & "?"
Style = vbYesNo + vbCritical + vbDefaultButton2
response = MsgBox(Message, Style, "Delete Activity Worksheet")
If response = vbNo Then Exit Sub
ActiveSheet.Delete
ActiveWorkbook.Sheets("Activities Inventory").Activate
Dim LRow As Long, n As Long
LRow = Range("B:B").End(xlUp).Row
For n = LRow To 1 Step -1
If Cells(n, 2).value = ActivityName Then Cells(n, 2).EntireRow.Delete
Next n
'ActiveWorkbook.Sheets("Menu").Select
'MsgBox "Please select the refresh button to update the Concerns Log.", vbInformation, "Update Log"
End Sub