Excel's Paste special has column widths but not row heights. This has always been irritating to me when I need to copy some rows and get them to apprear right, or fit on printout page, etc. So I wrote this routine, and am contributing it to the group.
Naturally, improvement or ehhancement ideas are welcome. I certainly expect that one of you can tighten up the first routine by a line or two. (Any other frustrated-ex-C/ASM-coding-perfectionist-dinosaurs out there? )
You can put this in your personal.xls and always have available. I pre-title all my personal macros with pm so they "clump together" in the list of macros when I run them. (If you do this, HIDE personal.xls, and it forms an unobtrusive set of ready-to-use utilities, like the following). Enjoy
'Initial draft - see bottom of thread for final "tweakation"
Sub pmRowHeightsCopy()
' select a range that has the row heights, run pmRowHeightsCopy;
' then move cursor to start of target to apply them to, and run pmRowHeightsPaste
Dim c As Range, i As Integer, iCol1 As Integer
iCol1 = Selection.Column
For Each c In Selection
If c.Column = iCol1 Then
i = i + 1
iHeights(i) = c.Height
End If
Next c
iHeightsCount = i
End Sub
Sub pmRowHeightsPaste()
' select a range that has the row heights, run pmRowHeightsCopy;
' then move cursor to start of target to apply them to, and run pmRowHeightsPaste
Dim c As Range, i As Integer
ActiveCell.Offset(0, 0).Select
For i = 1 To iHeightsCount
Set c = ActiveCell.Offset(0, 0)
c.RowHeight = iHeights(i)
ActiveCell.Offset(1, 0).Select
Next i
End Sub
Naturally, improvement or ehhancement ideas are welcome. I certainly expect that one of you can tighten up the first routine by a line or two. (Any other frustrated-ex-C/ASM-coding-perfectionist-dinosaurs out there? )
You can put this in your personal.xls and always have available. I pre-title all my personal macros with pm so they "clump together" in the list of macros when I run them. (If you do this, HIDE personal.xls, and it forms an unobtrusive set of ready-to-use utilities, like the following). Enjoy
'Initial draft - see bottom of thread for final "tweakation"
Sub pmRowHeightsCopy()
' select a range that has the row heights, run pmRowHeightsCopy;
' then move cursor to start of target to apply them to, and run pmRowHeightsPaste
Dim c As Range, i As Integer, iCol1 As Integer
iCol1 = Selection.Column
For Each c In Selection
If c.Column = iCol1 Then
i = i + 1
iHeights(i) = c.Height
End If
Next c
iHeightsCount = i
End Sub
Sub pmRowHeightsPaste()
' select a range that has the row heights, run pmRowHeightsCopy;
' then move cursor to start of target to apply them to, and run pmRowHeightsPaste
Dim c As Range, i As Integer
ActiveCell.Offset(0, 0).Select
For i = 1 To iHeightsCount
Set c = ActiveCell.Offset(0, 0)
c.RowHeight = iHeights(i)
ActiveCell.Offset(1, 0).Select
Next i
End Sub