I have this report and I want to increase the vertical cell padding to make it easier to read.

Now, typically you could just select multiple rows and change the row height until you're satisfied.

However, in this case, I have cells with wrapped text and multiple lines. I can't change change the the row height, because the wrapped text will get cut off.

What I want to do is increase the row height of a bunch of cells by a certain value. Rather than just change it to a specify value. ie.

rowheight = rowheight + X

Not

rowheight = X


Can you do this in excel? Will I need VBA?

link|improve this question

I'd guess you'll eventually have at least some VBA here. Therefore... I'd move this question to SO instead of keeping it here in SU. – Tiago Cardoso Aug 1 '11 at 14:36
I don't see any reason to. If VBA is required, your code is perfect. Just needs to be changed to use a selection rather than a static range. – user606723 Aug 1 '11 at 14:48
IMO... SU: Excel-only tricks and functions. SO: Excel/VBA related tricks and functions. – Tiago Cardoso Aug 1 '11 at 14:53
I guess the point is that... I could've done it with VBA myself. I was looking for a answer from the perspective. If I asked at SO.... I -definitely- would've gotten a VBA answer. – user606723 Aug 1 '11 at 15:00
So, your idea was to do it without using VBA? If so, you should've been clearer in your question... Anyways, I don't believe it's possible. – Tiago Cardoso Aug 1 '11 at 15:08
feedback

2 Answers

up vote 1 down vote accepted

I'd go for the code below... not sure if there would be a way to apply it for all rows once. I'd be glad (and upvote) if someone else here knows :)

Sub fixRowHeight()

Dim oRange As Excel.Range
Dim oRow As Excel.Range
Dim dblFactor As Double

Set oRange = Sheets(1).Range("A1:B25")
dblFactor = 5

For Each oRow In oRange.Rows

    oRow.RowHeight = oRow.RowHeight + dblFactor

Next oRow

End Sub
link|improve this answer
feedback

Here's a macro to help you out.

First it sets the vertical alignment for each cell to Center.

Next, it takes the current height of each cell and adds 7.5 to it (this is equivalent to 10 pixels). In the end, it adds a 5-pixel padding to the top and bottom part of the cell. Just adjust this value according to your preference.

Sub PadCells()

Set cr = Selection

For Each cr In cr.Rows
    newHeight = cr.RowHeight + 7.5 
    cr.VerticalAlignment = xlCenter
    cr.RowHeight = newHeight
Next cr

End Sub

To use:

  1. Select the cells for which you want to adjust the height.
  2. Run the macro.
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.