LoginSignup
0
0

More than 1 year has passed since last update.

エクセル、空っぽのシートを見つける

Last updated at Posted at 2021-07-21

エクセル、空っぽのシートを見つける

・すべてのシートをナメて、空のシートを見つけたい
・UsedRangeで、行・列いずれかが1でないものは、空ではない(はず)
・UsedRangeで、行・列いずれも1で、かつ、セル(1,1)が空なら、空のはず
・画像などが一つもない(Shapes.Count = 0)なら空のはず

という条件にしてます。

sample.bas
Sub 空っぽのシートを見つける()

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

Dim sht As Variant

  For Each sht In ActiveWorkbook.Sheets
        If sht.Visible <> xlSheetHidden Then
      sht.Select

       'Debug.Print sht.Name

        shtnm = sht.Name

        r = Sheets(shtnm).UsedRange.Cells(ActiveSheet.UsedRange.Count).Row
        c = Sheets(shtnm).UsedRange.Cells(ActiveSheet.UsedRange.Count).Column

        If r = 1 And c = 1 And _
            Sheets(shtnm).Cells(r, c).value & "" = "" And _
            Sheets(shtnm).Shapes.Count = 0 Then
            Debug.Print shtnm & " is Null"
        Else
            Debug.Print shtnm & " is not Null"
        End If
        'Sheets(shtnm). と sht. どっちでも動く
      End If
  Next
  'ActiveWorkbook.Sheets(1).Select

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic

End Sub

※参考

【エクセル】全シートのカーソルを左上にそろえる #ジョーク
https://qiita.com/santarou6/items/b4a556a49d1c5b7960e4

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