Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
brg brg is offline
external usenet poster
 
Posts: 15
Default Excell autofit row height function

I'm creating a worksheet where I want users to fill in free text data.
the autofit row height seems to work where individual cells are concerned.
My difficulty is that where cells have been merged (within a single row) the
function appears not to work.

any suggestions ?

--
later
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 747
Default Excell autofit row height function

Paste this to the worksheet's code module: Right click the sheet tab and
select View Code and then paste the code to the module. If you are protecting
the sheet then it needs to be modified. This is an adaption of code
originally written by Jim Rech.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim NewRwHt As Single
Dim cWdth As Single, MrgeWdth As Single
Dim c As Range, cc As Range
Dim ma As Range

With Target
If .MergeCells And .WrapText Then
Set c = Target.Cells(1, 1)
cWdth = c.ColumnWidth
Set ma = c.MergeArea
For Each cc In ma.Cells
MrgeWdth = MrgeWdth + cc.ColumnWidth
Next
Application.ScreenUpdating = False
On Error Resume Next
ma.MergeCells = False
c.ColumnWidth = MrgeWdth
c.EntireRow.AutoFit
NewRwHt = c.RowHeight
c.ColumnWidth = cWdth
ma.MergeCells = True
ma.RowHeight = NewRwHt
cWdth = 0: MrgeWdth = 0
On Error GoTo 0
Application.ScreenUpdating = True
End If
End With
End Sub

Regards,
Greg



Reply
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
Autofit for row height is not working. Why? Leo Excel Discussion (Misc queries) 3 July 28th 08 06:43 PM
Cell Displays ### and Won't AutoFit for Height Lori Excel Discussion (Misc queries) 5 March 20th 06 10:22 PM
Autofit Row Height MarkN Excel Discussion (Misc queries) 0 November 21st 05 03:38 AM
autofit height of row - ajit Ajit Munj Excel Discussion (Misc queries) 1 June 9th 05 02:04 PM
How to STOP autofit row height J Excel Discussion (Misc queries) 5 March 28th 05 06:39 PM


All times are GMT +1. The time now is 06:38 AM.

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

About Us

"It's about Microsoft Excel"