これはすべてのExcelバージョンで有効です。
Function cellsInRange(rng As Range) As Boolean
Dim cellsInCol As Long, cellsInRow As Long, cols As Long, count As Long, rws As Long
With ActiveSheet
cellsInCol = .Columns("A").Cells.count
cellsInRow = .Rows(1).Cells.count
End With
With rng
cols = .Columns.count
count = .Cells.count
rws = .Rows.count
End With
If cols = 1 And count = cellsInCol Then
cellsInRange = True
ElseIf rws = 1 And count = cellsInRow Then
cellsInRange = True
End If
End Function
編集
を、より具体的な詳細は、範囲のオブジェクトについて必要とされる場合は、以下の適応が有用であることを証明し得る:
Function cellsInRange(rng As Range) As String
Dim cellsInCol As Long, cellsInRow As Long, cols As Long, count As Long, rws As Long
With ActiveSheet
cellsInCol = .Columns("A").Cells.count
cellsInRow = Rows(1).Cells.count
End With
With rng
cols = .Columns.count
count = .Cells.count
rws = .Rows.count
End With
If cols = 1 And count = cellsInCol Then
cellsInRange = "Single column"
ElseIf rws = 1 And count = cellsInRow Then
cellsInRange = "Single row"
Else
cellsInRange = "Neither single column nor single row"
End If
End Function
の変数であることは、IMO、最良の方法です。 –
最新の回答をご覧ください。 – Miqi180
私が知っている組み込みプロパティはありませんが、 'Long'変数のmax rowsとcolumnsを保存します' maxRows = Rows.Count' – Slai