範囲を取得するには
SetSourceRange = Cells.SpecialCells(xlVisible)'全ての可視セル
SetSourceRange = Cells.SpecialCells(xlFormulas)'数式のセル
SetSourceRange = Cells.SpecialCells(xlConstants)'定数のセル
SetSourceRange = Cells.SpecialCells(xlConstants, xlTextValues)'定数で文字を含むセル
選択されている範囲を取得するにはオブジェクト式をCellsからSelectionに変更します。例えば
SetSourcerange = Selection.SpecialCells(xlVisible)'全ての可視セル
とします。
下のサンプルは選択されている範囲の行、列、値をイミディエイトウィンドウに出力します。
DimSourceRangeAsRange
DimitemAsVariant
'選択されている範囲を取得します。
Set sourcerange = Selection.SpecialCells(xlVisible)'選択されている全ての可視セル
'選択されているセルのループ
For Each item In SourceRange
Debug.Print item.Row & "行" & item.Column & "列" & item.Value
Next