text wrap and change row height on different cells in an excel sheet

A

asifkhanpathan

Hello there,

I've been trying to look for a way to wrap the text and display it in
the row by adjusting the row height. I have found a way of doing this
for a selected cell, however i need my macro to be able to traverse
through the sheet and perform the task. I am not familiar to vba
functions and would appreciate if some one could provide sugggestions
on how to achieve this.

In my case the cells aren't merged!
/*****************
Sub AutoFitMergedCellRowHeight()
Dim CurrentRowHeight As Single, MergedCellRgWidth As Single
Dim CurrCell As Range
Dim ActiveCellWidth As Single, PossNewRowHeight As Single
If ActiveCell.MergeCells Then
With ActiveCell.MergeArea
If .Rows.Count > 1 And .WrapText = True Then
Application.ScreenUpdating = False
CurrentRowHeight = .RowHeight
ActiveCellWidth = ActiveCell.ColumnWidth
For Each CurrCell In Selection
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
End Sub
***************/

Thank You
 
D

Dave Peterson

If the cells aren't merged, then autofitting the row height should work ok.

Option Explicit
sub testme01()
activesheet.usedrange.rows.autofit
end Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top