ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   sum height of selected rows (https://www.excelbanter.com/excel-discussion-misc-queries/216909-sum-height-selected-rows.html)

geotso

sum height of selected rows
 
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
--
Please, remove hyphens to contact me
--

Lars-Åke Aspelin[_2_]

sum height of selected rows
 
On Sun, 18 Jan 2009 06:27:00 -0800, geotso
wrote:

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
--
Please, remove hyphens to contact me



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

Mike H

sum height of selected rows
 
Hi,

You do do this

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

Mike

"geotso" wrote:

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
--
Please, remove hyphens to contact me
--


Lars-Åke Aspelin[_2_]

sum height of selected rows
 
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


On Sun, 18 Jan 2009 06:48:02 -0800, Mike H
wrote:

Hi,

You do do this

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

Mike

"geotso" wrote:

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
--
Please, remove hyphens to contact me
--



geotso

sum height of selected rows
 
"Mike H" wrote:

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

geotso

sum height of selected rows
 
"Lars-Ã…ke Aspelin" wrote:

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


All times are GMT +1. The time now is 06:08 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com