0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【エクセルVBA】複数シート一括で特定の値をもつ行を抽出し行削除するマクロ

Posted at

なかなかドンピシャなコードがweb上で見つからなかったので記録用に掲載。

Sub MultiSheetFilter_Delete_FillterFalse()
    Dim ws As Worksheet
    
    For Each ws In ThisWorkbook.Worksheets
    
    Dim targetRange As Range
    
        ws.Range("A1", "XFD1048576").AutoFilter Field:=2, Criteria1:="特定の値"
    
    With ws.Range("A1").CurrentRegion

        Set targetRange = .Offset(1, 0).Resize(Rows.Count - 1).SpecialCells(xlCellTypeVisible)
        
        targetRange.Delete shift:=xlUp
        
        ws.AutoFilterMode = False
    
    End With

    Next ws
End Sub

おそらくもっとシンプルに書けるのでしょうけど。。

ちなみに、

Set targetRange = .Offset(1, 0).Resize(Rows.Count - 1).SpecialCells(xlCellTypeVisible)

の部分の

Resize(Rows.Count - 1)

は、

Resize(.Rows.Count - 1)

とするweb記事が多かったのですが、下記環境ではエラーになったので補足します。

macOS, office365

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?