Share via

Delete Active Sheet

Anonymous
2014-10-04T14:58:58+00:00

Hi,

I have a macro that deletes the active sheet I am on, but the problem is that when the active sheet is the only sheet I have unhidden and the rest hidden. How could the macro could be able to notice if the active sheet I am going to delete is the last sheet so that before the deletion of that active sheet occurs it unhides another sheet called "Main Menu" and than it deletes the active sheet.

Thanks 

Owen

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2014-10-04T15:07:11+00:00

Hi,

You could do this.

Sub CountEm()

Dim ws As Worksheet, i As Long

For Each ws In ActiveWorkbook.Worksheets

        i = i - ws.Visible

Next

If i = 1 Then

    Sheets("Main Menu").Visible = True

End If

Application.DisplayAlerts = False

    ActiveSheet.Delete

Application.DisplayAlerts = True

End Sub

Was this answer helpful?

0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. Anonymous
    2014-10-04T21:03:59+00:00

    Thanks Mike for your assistance.

    Was this answer helpful?

    0 comments No comments