VBA code to sum the row heights of every row in the Print_Area range of a worksheet

Mauritz

Board Regular
Joined
Dec 15, 2006
Messages
53
I am looking for VBA code to sum the row heights of every row in the Print_Area range of a worksheet please.

For example if the print range is 10 rows and each row is 15 points then the result will be 150 points (PS. The row heights differ on the various rows in the print range of each page, and there are numerous worksheet pages to be checked).

The second part of my problem is to improve this code so that it will also add the page margins and Print Titles to the above result.

I am using Excel 2016 on Windows 7 Professional
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
I would use something like this, however I'm not sure what the Print_Area is exactly so I have used the UsedRange property of the worksheet instead.
Assuming that your data starts from the first row, a message with the total row height will pop-up on screen...

Code:
Sub test()

    Dim r As Long, lastrow As Long
    Dim TotalRowHeight As Double
    
    lastrow = Worksheets("Sheet1").UsedRange.Rows.Count
    
    For r = 1 To lastrow
        TotalRowHeight = TotalRowHeight + Rows(r).RowHeight
        
    Next r
    
    MsgBox TotalRowHeight
    

End Sub
 
Upvote 0
Thanks for your reply. I am currently using the following code but the trick for me is to add the height of the page margins and the print titles as well.

Code:
Sub PageHeight()

    MsgBox "Page Height: " & ActiveSheet.Range(ActiveSheet.PageSetup.PrintArea).Height

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,314
Members
452,634
Latest member
cpostell

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top