0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

対象シート以外を削除する

Posted at

VBAでシートを削除

Sub DeleteAllSheetsExceptOne()
Dim sheet As Worksheet
Dim sheetToKeep As Worksheet
Dim sheetNameToKeep As String

sheetNameToKeep = "Sheet1" ' 保持するシートの名前を指定してください

Application.DisplayAlerts = False ' 確認ダイアログを非表示にする場合

For Each sheet In ThisWorkbook.Sheets
    If sheet.Name <> sheetNameToKeep Then
        sheet.Delete
    Else
        Set sheetToKeep = sheet
    End If
Next sheet

Application.DisplayAlerts = True

If Not sheetToKeep Is Nothing Then
    sheetToKeep.Activate
    MsgBox "指定されたシート以外が削除されました。"
Else
    MsgBox "指定されたシートが見つかりませんでした。"
End If

End Sub

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?