Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

delete cell on different sheet if cell is empty

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading