0

The following Sub procedure was working fine, but has suddenly started throwing an error.

Sub DeleteAll()

Cells.Select
Selection.Delete Shift:=xlUp
Cells.Select

End Sub

Error enter image description here

What could be the reason for the error?

HKS
  • 356
  • 2
  • 20
  • 1
    Side note: generally it is best to [avoid using Select](https://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba) (and `Selection`) to begin with. – BigBen May 19 '22 at 16:40
  • 1
    If your intention is to clear the sheet use `Cells.Clear` then `ActiveSheet.UsedRange` or better yet, just delete it – Sgdva May 19 '22 at 16:42
  • @Cyril My question is: why is the Sub procedure throwing an error now when it was working just fine a few days ago? – HKS May 19 '22 at 16:48
  • @HKS do you have a subroutine named `Selection`? That typically causes this error. If you are only just having this issue, then you may have created this in another module by mistake. – Cyril May 19 '22 at 16:54
  • aside from @cyril comment, missing references also may cause odd behaviour. Check if you do not have errors under tools->references – Sgdva May 19 '22 at 17:06

0 Answers0