Row Height

snapper1969

Board Regular
Joined
Apr 3, 2008
Messages
122
Hi,

I have the following code that formats and sizes a range.

Sub FlexFormFormat()
'
' Keyboard Shortcut: Ctrl+w
'
Columns("C:C").Select
Selection.ColumnWidth = 7
Columns("D:D").Select
Selection.ColumnWidth = 50
Range("D10:E27").Select
With Selection
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.ReadingOrder = xlContext
End With
Range("D10:E27").Select
Selection.RowHeight = 45
End Sub

Is it possible to change the row height only of the rows that need it to enable all the text in those to be visible.

Thx,

John
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Maybe something like this may work, but I can't test it at the moment:

Code:
rows("10:27").autofit

Hope that helps.
 
Last edited:
Upvote 0
Try:

Code:
Sub FlexFormFormat()
'
' Keyboard Shortcut: Ctrl+w
'
Columns("C:C").ColumnWidth = 7
Columns("D:D").ColumnWidth = 50
With Range("D10:E27")
    .VerticalAlignment = xlBottom
    .WrapText = True
    .Orientation = 0
    .AddIndent = False
    .ShrinkToFit = False
    .ReadingOrder = xlContext
    .EntireRow.AutoFit
End With
End Sub

Hope it helps,

Dom
 
Upvote 0
Guys,

Thx for that, autofit works great. I had to unmerge columns d and e as that was causing a problem with the autofit.

Is there a way to select the range as the ending row will be different each time?.

Thx,

John
 
Upvote 0
Modifying the code you can use:

Code:
Sub FlexFormFormat()
'
' Keyboard Shortcut: Ctrl+w
'
LC = cells(rows.count,"D").end(xlup).row
Columns("C:C").ColumnWidth = 7
Columns("D:D").ColumnWidth = 50
With Range("D10:E" & LC)
    .VerticalAlignment = xlBottom
    .WrapText = True
    .Orientation = 0
    .AddIndent = False
    .ShrinkToFit = False
    .ReadingOrder = xlContext
    .EntireRow.AutoFit
End With
End Sub
Hope that helps.
 
Upvote 0

Forum statistics

Threads
1,215,002
Messages
6,122,652
Members
449,092
Latest member
peppernaut

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