LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 169
Default Autofit doesn't work when column not enough width

Hi !
I have modify the original "AdjustRowHeight" for merged cells to apply to
all cells in a specific table range. Sometimes, when column width are not
enought large, the EntireRow.AutoFit command doesn't work. Does anyone have a
solution for this kind of problem ?
Is it possible to have a macro that replace the Autofit line ?
What I could do is to enlarge each table column (+1), make autofit and then,
resize column width to original value.

Excel seems to required a little space after the end of the last character.

Thank you.

Here is my program.
Sub AdjustRowHeight()
Dim myRange As Range
Dim CurrentRowHeight As Single, MergedCellRgWidth As Single
Dim CurrCell As Range
Dim ActiveCellWidth As Single, PossNewRowHeight As Single
Dim j As Long
Dim myCell As Cells

'1- Verify if there is a table in the ActiveSheet
myTable = Array("table1_1", "table1_2", "table2_1", "table2_2", "table2_3",
"table3_1", "table3_2")
On Error Resume Next
i = -1
Do Until Not myRange Is Nothing Or i = 7
i = i + 1
Set myRange = ActiveSheet.Range(myTable(i)) 'Local Range Only
Loop
If i = 7 Then Exit Sub

'2- Adjust Row Height
myRange.EntireRow.AutoFit = True
For Each cell In myRange
MergedCellRgWidth = 0
If cell.MergeCells And cell = cell.MergeArea.Cells(1) Then 'Treatment
for first merge cell only
With cell.MergeArea
If .Rows.Count = 1 And .WrapText = True Then
Application.ScreenUpdating = False
CurrentRowHeight = .RowHeight
ActiveCellWidth = cell.ColumnWidth
For Each CurrCell In cell.MergeArea
MergedCellRgWidth = CurrCell.ColumnWidth +
MergedCellRgWidth
Next
.MergeCells = False
.Cells(1).ColumnWidth = MergedCellRgWidth
.EntireRow.AutoFit
PossNewRowHeight = .RowHeight
.Cells(1).ColumnWidth = ActiveCellWidth
.MergeCells = True
.RowHeight = IIf(CurrentRowHeight PossNewRowHeight, _
CurrentRowHeight, PossNewRowHeight)
End If
End With
End If
Next cell
End Sub
--
Alex St-Pierre
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
format:column width: autofit selection dutch3dsmax Setting up and Configuration of Excel 1 March 28th 07 08:27 AM
autofit cells in column width Boethius1 Excel Discussion (Misc queries) 5 April 12th 06 02:51 AM
Autofit Row height or Column Width does not work Gunjani Excel Discussion (Misc queries) 2 October 11th 05 09:19 PM
autofit Column width- Ajit Ajit Munj Excel Discussion (Misc queries) 2 February 24th 05 05:51 PM
Autofit column width of all worksheets in active workbook - an example DataFreakFromUtah Excel Programming 1 June 18th 04 11:24 PM


All times are GMT +1. The time now is 07:33 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"