Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / September 2007

Tip: Looking for answers? Try searching our database.

AutoFit - Merged Cells

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
David A. - 25 Sep 2007 21:44 GMT
Hey,
I have a row with a series of merged cells in it, (b43:m43, makes up the
merged cell). I need to autofit text in that merged cell. Every time I use
AutoFit it shrinks the entire row to one line (12.50). How do I get it to
autofit based on what is in the merged cells b43:m43? This has been driving
me crasy for a week now.

Thanx
Gord Dibben - 26 Sep 2007 00:01 GMT
Long audible sigh here.................

One more victim of "merged cells".

It may be better to use the "Center Across Selection" from
Cells>Format>Alignment.

Wrap Text works fine on merged cells, but Autofit does not work.

You need VBA event code to do that.

Here is code from Greg Wilson.

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
    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
Application.ScreenUpdating = True
End If
End With
End Sub

This is event code.  Right-click on the sheet tab and "View Code".

Copy/paste the code into that sheet module.

Gord Dibben  MS Excel MVP

>Hey,
>I have a row with a series of merged cells in it, (b43:m43, makes up the
[quoted text clipped - 4 lines]
>
>Thanx
Bill Renaud - 26 Sep 2007 00:29 GMT
I believe that merged cells to not participate in AutoFit operations. You
might have to write a macro to copy the contents to a new, temporary
worksheet, AutoFit the cell there, measure the width of that cell, then set
the width of the cell on your original worksheet to this value.

Does this range have Wrap Text turned on? Do you want the row height to be
a multiple of the normal row height? Then you have an even more complex
problem at hand.
Signature

Regards,
Bill Renaud

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.