I am trying to clean up my workbook by deleting some cells on another sheet if the cells are empty (Later on I also need to remove a Column on another sheet)
unfortunately this just deletes the cells on the sheet containing the button
I tried the following:
(edited)
Sub Delete_cells()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Sheets
If ws.Name = "Inlife" Or ws.Name Like "'Inlife (*)'" Then
If Range("C22") = "" Then
Range("B22:C22").Delete Shift:=xlUp
If Range("C23") = "" Then
Range("B23:C23").Delete Shift:=xlUp
End If
End If
End If
Next ws
End Sub
Can anyone help me get back on track?
>Solution :
What about this:
...
For Each ws In ThisWorkbook.Sheets
If ws.Name = "Inlife" Or ws.Name Like "'Inlife (*)'" Then
If ws.Range("C22").Value = "" AND ws.Range("C23").Value = "" Then
ws.Range("B22:C23").Delete Shift:=xlUp
End If
End If
Next ws
End Sub
You can’t check different cells at once, you need to check all of them separately.