可視セルのみ選択/値を取得するコードサンプル
SpecialCellsメソッドを使用する事で、可視セルのアクティブ化、可視セルのデータをコピー等する事が可能です。
可視セルは
Hidden状態やオートフィルタがかかった状態を指します。
Public Sub sample()
'■エラーが出た行を無視する
On Error Resume Next
'■セルA1を含む表の空白セルのみ選択する
Range("A1").CurrentRegion.SpecialCells(xlCellTypeVisible).Select
'■セルA1を含む表の空白セルの個数をカウントする
Debug.Print Range("A1").CurrentRegion.SpecialCells(xlCellTypeVisible).Count
'■セルA1を含む表の空白セルのアドレスを表示する(空白セルを検索する)
Debug.Print Range("A1").CurrentRegion.SpecialCells(xlCellTypeVisible).Address
'■セルA1:C5の可視セルのみ選択する
Range("A1:C5").SpecialCells(xlCellTypeVisible).Select
'■Sheet2へSheet1のセルA1:C5の可視セルをコピペする
Worksheets("Sheet1").Range("A1:C5").SpecialCells(xlCellTypeVisible).Copy
Worksheets("Sheet2").Range("A1").PasteSpecial
End Sub
注意点
関連記事
コメント