Excel Macro: can I find row heights and column widths of a worksheet?

Is there any way to find the ROWS height from 1 to 50 and the COLUMNS width from A to Z on an Excel worksheet without manually clicking and recording the response?

thank

Michael.

+5
source share
3 answers

To add on top of @Parkyprg

Range("A1:A50").Height      ' height of range
Range("A:Z").Width          ' width of range
Range("A1:A50").Rows.Count  ' number or rows in range
Range("A3").Height          ' height of A3 cell
Range("A3").Width           ' width of A3 cell
+6
source

In Excel VBA, you can use something like this:

Range("A1:A50").Height  

and

Range("A:Z").Width
+3
source

Excel vba rows.height:

Sub outputRowHeight()
    Dim i As Integer

    For i = 1 To 50
         Debug.Print Rows(i).Address & " is : " & Rows(i).Height
    Next i

End Sub

columns.width. , , :

Sub outputColumnWidths1()
    Dim i As Integer

    For i = 1 To 26 '26th letter is Z
            Debug.Print Columns(i).Address & " is : " & Columns(i).Width
    Next i

End Sub

, , if :

Sub outputColumnWidths2()
    Dim i As Integer

    For i = 1 To 99 'using 99 as arbitrary high end number
        If Columns(i).Address <> "$AA:$AA" Then
            Debug.Print Columns(i).Address & " is : " & Columns(i).Width
        Else 'once we get outside of A-Z, we want to end.
            Exit For
        End If
    Next i

End Sub

This will produce the same results as in the first example, but you can expand it to the number of columns you want by typing the iteration number and the first column name of the first that you do not want to evaluate.

Hope this helps!

0
source

All Articles