Sub remove_customers()
Dim cnt, count, lrow, lastrow As Long
Dim sheetname, customer, company, owner As String
lrow = Worksheets("Master").Cells(Rows.count, 1).End(xlUp).Row
For cnt = 2 To lrow
customer = Worksheets("Master").Cells(cnt, 2).Value
company = Worksheets("Master").Cells(cnt, 3).Value
owner = Worksheets("Master").Cells(cnt, 4).Value
sheetname = customer & ", " & company & ", " & owner
If SheetExists(sheetname) Then 'check you have a customer worksheet of that name in the workbook (using private function below)
lastrow = Worksheets(sheetname).Cells(Rows.count, 1).End(xlUp).Row 'get last row of customer sheet
For count = lastrow To 2 Step -1 'now search through the list to delete unwanted items
If Worksheets(sheetname).Cells(count, 2) <> customer And Worksheets(sheetname).Cells(count, 3) <> company And Worksheets(sheetname).Cells(count, 4) <> owner Then
Worksheets(sheetname).Cells(count, 2).EntireRow.Delete
End If
Next count
Else
MsgBox ("Customer '" & sheetname & "' has no sheet")
End If
Next cnt
End Sub
Private Function SheetExists(Tabname) As Boolean
' Returns TRUE if sheet exists in the active workbook
Dim x As Object
On Error Resume Next
Set x = ActiveWorkbook.Sheets(Tabname)
If Err = 0 Then SheetExists = True _
Else SheetExists = False
End Function