Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Navin Gada   on Jan 05 In MS Office Category.

  
Question Answered By: Fairuzah Alam   on Jan 05

I think that the problem  is that when it sets up the for each sheet  it
identifies that there are, say 7 sheets. When it deletes one it does not
alter this number. so it eventually gets to a non-existent sheet.

Try doing it backwards

something like (untested code)

for x = worksheets.count to 1 step -1
With worksheets(x)
If IsDate(.Name) Then
If DateValue(.Name) <= DateValue(Date - 14) Then
Application.DisplayAlerts = False
.Delete
End If

End If


Next x

Share: 

 

This Question has 2 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Delete Sheet Problem, Excel Crash ! Or get search suggestion and latest updates.


Tagged: