xlf | GetSelectDim macro
GetSelectDim - about the macro
Description: returns the dimension (number of rows and number of columns) of the Excel selection.
The dimension information is displayed in a message box. Example output is shown in figure 1.

GetSelectDim - the VBA code
Code 1: Macro
GetSelectDim returns the dimension of the Excel selection
Sub GetSelectDim()
Dim NoCols As Integer, NoRows As Long
Dim Srows As String, Scols As String
NoCols = Selection.Columns.Count
NoRows = Selection.rows.Count
If NoCols = 1 Then
Scols = " column"
Else
Scols = " columns"
End If
If NoRows = 1 Then
Srows = " row x "
Else
Srows = " rows x "
End If
MsgBox "Selection dimension: " _
& NoRows & Srows & NoCols & Scols _
& " [" & NoRows & "R X " & NoCols & "C]" _
& vbNewLine & vbNewLine & "Coded by ExcelAtFinance " & Chr(169) & Chr(32) & Year(Date), _
vbInformation, "About the selection"
End Sub
- This example was developed in Excel 2013 Pro 64 bit.
- Revised: Friday 24th of February 2023 - 02:37 PM, Pacific Time (PT)
