sum height of selected rows

G

geotso

Is there an easy way to calculate the total height of selected rows?
eg, when I select 30 rows, where some or all of them have different heights,
how can I calculate the total height of the selection?

Even better, is there a VBA script for this?
Excel 2007

Thanks
 
L

Lars-Åke Aspelin

Is there an easy way to calculate the total height of selected rows?
eg, when I select 30 rows, where some or all of them have different heights,
how can I calculate the total height of the selection?

Even better, is there a VBA script for this?
Excel 2007

Thanks


If your selection is contiguous, i.e. without any gaps, you may try
this macro:

Sub height_of_selected_rows()
h = 0
For i = Selection.Row To Selection.Row + Selection.Rows.Count - 1
h = h + Cells(i, 1).height
Next i
MsgBox "The sum of heights of the selected rows is " & h
End Sub

Hope this helps / Lars-Åke
 
M

Mike H

Hi,

You do do this

For Each c In Selection
TotHeight = TotHeight + c.RowHeight
Next
MsgBox TotHeight

Mike
 
L

Lars-Åke Aspelin

I don't think that we can assume that the selection is limited to one
column, especially as the OP writes that "30 rows" are selected.

Lars-Åke
 
G

geotso

Mike H said:
Hi,

You do do this

For Each c In Selection
TotHeight = TotHeight + c.RowHeight
Next
MsgBox TotHeight

Mike
I get a message "12779520" for my selection (an example of 32 rows). What
does that mean?

Thanks
 
G

geotso

:

If your selection is contiguous, i.e. without any gaps, you may try
this macro:

Sub height_of_selected_rows()
h = 0
For i = Selection.Row To Selection.Row + Selection.Rows.Count - 1
h = h + Cells(i, 1).height
Next i
MsgBox "The sum of heights of the selected rows is " & h
End Sub

Hope this helps / Lars-Ã…ke
I've tried it and works like a charm!

Thank you very much
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top