views:

209

answers:

3

When I orient column headers at 45º I have to manually resize each column since Auto-Fit won't let the oriented text overlap with the neighboring cell.

Is there a way to programatically (with VBA) auto-fit the columns where they'll overlap? I'd like a solution which takes font size into account too.

A: 
SheetName.Range("a:c").Columns.EntireColumn.AutoFit

Will autofit columns a - c in Sheet SheetName. Is this what you were looking for?

Russ Cam
A: 

What you need to do is autofit to the cell range excluding the header row:

Sub autofitToRange()
    Range("B2:F5").Columns.AutoFit
End Sub

Instead of:

Sub autofitFullColumns()
    Range("B:F").Columns.AutoFit
End Sub
Lunatik
+1  A: 

AutoFit only works on non 0º oriented text when the cell with the oriented text has borders set. Odd...

AnotherOne