参考元:【VBA】可視セルや空白セルの位置を取得【SpecialCellsを使う】
https://daitaideit.com/vba-specialcells/

SpecialCellsの使い方
'コメント
Cells.SpecialCells(xlCellTypeComments).Select
'定数
Cells.SpecialCells(xlCellTypeConstants).Select 'すべて
Cells.SpecialCells(xlCellTypeConstants, 1).Select '数値
Cells.SpecialCells(xlCellTypeConstants, 2).Select '文字
'数式
Cells.SpecialCells(xlCellTypeFormulas).Select 'すべて
Cells.SpecialCells(xlCellTypeFormulas, 1).Select '数値
Cells.SpecialCells(xlCellTypeFormulas, 2).Select '文字
Cells.SpecialCells(xlCellTypeFormulas, 16).Select 'エラー
'空白セル
Cells.SpecialCells(xlCellTypeBlanks).Select
'最後のセル
Cells.SpecialCells(xlCellTypeLastCell).Select
'可視セル
Range("A1").CurrentRegion.SpecialCells(xlCellTypeVisible).Select
'条件付き書式
Cells.SpecialCells(xlCellTypeAllFormatConditions).Select 'すべて
Range("A1").SpecialCells(xlCellTypeSameFormatConditions).Select '同じ条件
'データの入力規則
Cells.SpecialCells(xlCellTypeAllValidation).Select 'すべて
Range("A1").SpecialCells(xlCellTypeSameValidation).Select '同じ規則
例:コメントのセルを選択

Sub TEST1()
    
    'コメントのセルを選択
    Cells.SpecialCells(xlCellTypeComments).Select
    
End Sub
実行結果:

■可視セルを選択して不要行を削除
▼可視セルのみを削除
使う表

Sub TEST16()
    
    'A列で「A」以外である行を非表示
    For i = 2 To Cells(Rows.Count, "A").End(xlUp).Row
        If Cells(i, "A") <> "A" Then
            Rows(i).Hidden = True '非表示
        End If
    Next
    
    '表全体の値のみを取得
    With Range("A1").CurrentRegion.Offset(1, 0)
        .Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).Delete
    End With
    
    'すべての行を表示
    Rows("1:100").Hidden = False
    
End Sub
手順としては、
①A列が『A』以外である行を非表示にする
②表全体の値のみを取得する
③可視セルを削除する
④行をすべて表示する
実行結果:

▼オートフィルタで表示行のみを削除
Sub TEST17()
    
    'A列を、「A」でフィルタ
    Range("A1").AutoFilter 1, "A"
    
    'フィルタした行を削除
    With Range("A1").CurrentRegion.Offset(1, 0)
        .Resize(.Rows.Count - 1).EntireRow.Delete
    End With
    
    'フィルタを解除
    Range("A1").AutoFilter
    
End Sub
VBAコードの流れとしては、
①オートフィルタでA列を『"A"』でフィルタ
②表示している行を削除
③フィルタを解除
という感じです。
実行結果:

 
                     
                    
                 
                    
                 
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号