ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Merged cells won't Autofit row height (https://www.excelbanter.com/excel-discussion-misc-queries/125891-merged-cells-wont-autofit-row-height.html)

Hpyifur

Merged cells won't Autofit row height
 
When I merge cells and then choose the wrap text option the Autofit function
no longer works. Is there a way to get around this without manually sizing
the row each time?

ExcelBanter AI

Answer: Merged cells won't Autofit row height
 
Unfortunately, when you merge cells and then choose the wrap text option, the Autofit function won't work as expected. This is because Excel treats merged cells as a single entity, and the Autofit function only works on individual cells. However, there are a few workarounds you can try to get around this issue.
  1. Use the "Center Across Selection" option instead of merging cells: Instead of merging cells, you can use the "Center Across Selection" option to center the text across multiple cells. This will allow you to use the Autofit function on each individual cell, and the text will still appear as if it's in a merged cell. Here's how to do it:

    - Select the cells you want to center the text across.
    - Right-click on the selection and choose "Format Cells".
    - In the "Alignment" tab, choose "Center Across Selection" from the "Horizontal" dropdown menu.
    - Click "OK" to apply the formatting.
  2. Use a formula to combine the text: If you need to merge cells for a specific reason, you can use a formula to combine the text from the merged cells into a single cell. Here's how to do it:

    - In a new cell, type the formula
    Formula:

    "=A1&" "&B1" 

    , where A1 and B1 are the cells you want to merge.
    - Press Enter to apply the formula.
    - Copy the formula down to the other cells in the column.

    This will combine the text from the two cells into a single cell, which you can then use the Autofit function on.
  3. Use VBA code to Autofit merged cells: If you're comfortable with VBA code, you can use a macro to Autofit merged cells. Here's an example of the code you can use:

    Formula:

    Sub AutoFitMergedCells()
       
    Dim cell As Range
       
    For Each cell In Selection
           
    If cell.MergeCells Then
               cell
    .MergeArea.WrapText True
               cell
    .MergeArea.Rows.AutoFit
           End 
    If
       
    Next cell
       End Sub 

    To use this code, select the merged cells you want to Autofit, and then run the macro. The code will loop through each cell in the selection, and if it's a merged cell, it will set the "WrapText" property to true and then Autofit the rows.

    I hope one of these solutions works for you!

RagDyeR

Merged cells won't Autofit row height
 
*Unmerge* the cells and then use "Center Across Selection" from:

<Format <Cells. <Alignment tab,
Expand the "Horizontal" window and choose "Center Across Selection".
--
HTH,

RD

---------------------------------------------------------------------------
Please keep all correspondence within the NewsGroup, so all may benefit !
---------------------------------------------------------------------------
"Hpyifur" wrote in message
...
When I merge cells and then choose the wrap text option the Autofit
function
no longer works. Is there a way to get around this without manually
sizing
the row each time?



Hpyifur

Merged cells won't Autofit row height
 
RD - Thanks for your response.

My problem is that it's an area that needs to have information entered into
by other people (and could vary greatly as to the input). It has to be left
justified and is limited on how wide the merged area can be, that's why I was
looking to use the Wrap Text option.

Thanks
-----------------------------

"RagDyer" wrote:

*Unmerge* the cells and then use "Center Across Selection" from:

<Format <Cells. <Alignment tab,
Expand the "Horizontal" window and choose "Center Across Selection".
--
HTH,

RD

---------------------------------------------------------------------------
Please keep all correspondence within the NewsGroup, so all may benefit !
---------------------------------------------------------------------------
"Hpyifur" wrote in message
...
When I merge cells and then choose the wrap text option the Autofit
function
no longer works. Is there a way to get around this without manually
sizing
the row each time?




Gord Dibben

Merged cells won't Autofit row height
 
Long audible sigh here.................

One more victim of "merged cells".

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

You need VBA 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


Gord Dibben MS Excel MVP

On Fri, 12 Jan 2007 09:42:00 -0800, Hpyifur
wrote:

RD - Thanks for your response.

My problem is that it's an area that needs to have information entered into
by other people (and could vary greatly as to the input). It has to be left
justified and is limited on how wide the merged area can be, that's why I was
looking to use the Wrap Text option.

Thanks
-----------------------------

"RagDyer" wrote:

*Unmerge* the cells and then use "Center Across Selection" from:

<Format <Cells. <Alignment tab,
Expand the "Horizontal" window and choose "Center Across Selection".
--
HTH,

RD

---------------------------------------------------------------------------
Please keep all correspondence within the NewsGroup, so all may benefit !
---------------------------------------------------------------------------
"Hpyifur" wrote in message
...
When I merge cells and then choose the wrap text option the Autofit
function
no longer works. Is there a way to get around this without manually
sizing
the row each time?





Chris

Merged cells won't Autofit row height
 
Gord
I to used you code, works great, however not if I protected document. Any
suggestions?
--
Regards


"Gord Dibben" wrote:

Long audible sigh here.................

One more victim of "merged cells".

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

You need VBA 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


Gord Dibben MS Excel MVP

On Fri, 12 Jan 2007 09:42:00 -0800, Hpyifur
wrote:

RD - Thanks for your response.

My problem is that it's an area that needs to have information entered into
by other people (and could vary greatly as to the input). It has to be left
justified and is limited on how wide the merged area can be, that's why I was
looking to use the Wrap Text option.

Thanks
-----------------------------

"RagDyer" wrote:

*Unmerge* the cells and then use "Center Across Selection" from:

<Format <Cells. <Alignment tab,
Expand the "Horizontal" window and choose "Center Across Selection".
--
HTH,

RD

---------------------------------------------------------------------------
Please keep all correspondence within the NewsGroup, so all may benefit !
---------------------------------------------------------------------------
"Hpyifur" wrote in message
...
When I merge cells and then choose the wrap text option the Autofit
function
no longer works. Is there a way to get around this without manually
sizing
the row each time?





Greg Wilson

Merged cells won't Autofit row height
 
In place of the word "password" you would hard code your password and remove
the leading apostrophe assuming it's password protected. Otherwise ignore it.
Minimal testing:-

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
Dim ProtectStatus As Boolean

With Target
If .MergeCells And .WrapText Then
ProtectStatus = Me.ProtectContents
If ProtectStatus Then Me.Unprotect ' "password"
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
If ProtectStatus Then Me.Protect ' "password"
End If
End With
End Sub

Regards,
Greg




"Chris" wrote:

Gord
I to used you code, works great, however not if I protected document. Any
suggestions?
--
Regards


"Gord Dibben" wrote:

Long audible sigh here.................

One more victim of "merged cells".

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

You need VBA 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


Gord Dibben MS Excel MVP

On Fri, 12 Jan 2007 09:42:00 -0800, Hpyifur
wrote:

RD - Thanks for your response.

My problem is that it's an area that needs to have information entered into
by other people (and could vary greatly as to the input). It has to be left
justified and is limited on how wide the merged area can be, that's why I was
looking to use the Wrap Text option.

Thanks
-----------------------------

"RagDyer" wrote:

*Unmerge* the cells and then use "Center Across Selection" from:

<Format <Cells. <Alignment tab,
Expand the "Horizontal" window and choose "Center Across Selection".
--
HTH,

RD

---------------------------------------------------------------------------
Please keep all correspondence within the NewsGroup, so all may benefit !
---------------------------------------------------------------------------
"Hpyifur" wrote in message
...
When I merge cells and then choose the wrap text option the Autofit
function
no longer works. Is there a way to get around this without manually
sizing
the row each time?





Odie

Merged cells won't Autofit row height
 
Is there any solution for this problem without the use of code?

"Gord Dibben" wrote:

Long audible sigh here.................

One more victim of "merged cells".

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

You need VBA 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


Gord Dibben MS Excel MVP

On Fri, 12 Jan 2007 09:42:00 -0800, Hpyifur
wrote:

RD - Thanks for your response.

My problem is that it's an area that needs to have information entered into
by other people (and could vary greatly as to the input). It has to be left
justified and is limited on how wide the merged area can be, that's why I was
looking to use the Wrap Text option.

Thanks
-----------------------------

"RagDyer" wrote:

*Unmerge* the cells and then use "Center Across Selection" from:

<Format <Cells. <Alignment tab,
Expand the "Horizontal" window and choose "Center Across Selection".
--
HTH,

RD

---------------------------------------------------------------------------
Please keep all correspondence within the NewsGroup, so all may benefit !
---------------------------------------------------------------------------
"Hpyifur" wrote in message
...
When I merge cells and then choose the wrap text option the Autofit
function
no longer works. Is there a way to get around this without manually
sizing
the row each time?





Dave Peterson

Merged cells won't Autofit row height
 
Adjust the rowheight manually????

Odie wrote:

Is there any solution for this problem without the use of code?

"Gord Dibben" wrote:

Long audible sigh here.................

One more victim of "merged cells".

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

You need VBA 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


Gord Dibben MS Excel MVP

On Fri, 12 Jan 2007 09:42:00 -0800, Hpyifur
wrote:

RD - Thanks for your response.

My problem is that it's an area that needs to have information entered into
by other people (and could vary greatly as to the input). It has to be left
justified and is limited on how wide the merged area can be, that's why I was
looking to use the Wrap Text option.

Thanks
-----------------------------

"RagDyer" wrote:

*Unmerge* the cells and then use "Center Across Selection" from:

<Format <Cells. <Alignment tab,
Expand the "Horizontal" window and choose "Center Across Selection".
--
HTH,

RD

---------------------------------------------------------------------------
Please keep all correspondence within the NewsGroup, so all may benefit !
---------------------------------------------------------------------------
"Hpyifur" wrote in message
...
When I merge cells and then choose the wrap text option the Autofit
function
no longer works. Is there a way to get around this without manually
sizing
the row each time?





--

Dave Peterson

Odie

Merged cells won't Autofit row height
 
Dave, thanks. I guess I should have been more specific.

Is there anyway to make the autofit work with merged cells (other than using
code)? I have a form that is used over and over, so it's a pain to keep
manually adjusting (plus the screen view is different than print view, so it
means lots of switching back and forth).

Another work around that doesn't solve the underlying problem is to redesign
the form.

"Dave Peterson" wrote:

Adjust the rowheight manually????

Odie wrote:

Is there any solution for this problem without the use of code?

"Gord Dibben" wrote:

Long audible sigh here.................

One more victim of "merged cells".

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

You need VBA 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


Gord Dibben MS Excel MVP

On Fri, 12 Jan 2007 09:42:00 -0800, Hpyifur
wrote:

RD - Thanks for your response.

My problem is that it's an area that needs to have information entered into
by other people (and could vary greatly as to the input). It has to be left
justified and is limited on how wide the merged area can be, that's why I was
looking to use the Wrap Text option.

Thanks
-----------------------------

"RagDyer" wrote:

*Unmerge* the cells and then use "Center Across Selection" from:

<Format <Cells. <Alignment tab,
Expand the "Horizontal" window and choose "Center Across Selection".
--
HTH,

RD

---------------------------------------------------------------------------
Please keep all correspondence within the NewsGroup, so all may benefit !
---------------------------------------------------------------------------
"Hpyifur" wrote in message
...
When I merge cells and then choose the wrap text option the Autofit
function
no longer works. Is there a way to get around this without manually
sizing
the row each time?





--

Dave Peterson


Gord Dibben

Merged cells won't Autofit row height
 
You were quite specific as was Dave's answer.

Without code you must manually adjust the heights.

Blow away those merged cells and forget that feature exists to make life much
simpler.


Gord Dibben MS Excel MVP

On Thu, 28 Jun 2007 09:02:02 -0700, Odie wrote:

Dave, thanks. I guess I should have been more specific.

Is there anyway to make the autofit work with merged cells (other than using
code)? I have a form that is used over and over, so it's a pain to keep
manually adjusting (plus the screen view is different than print view, so it
means lots of switching back and forth).

Another work around that doesn't solve the underlying problem is to redesign
the form.

"Dave Peterson" wrote:

Adjust the rowheight manually????

Odie wrote:

Is there any solution for this problem without the use of code?

"Gord Dibben" wrote:

Long audible sigh here.................

One more victim of "merged cells".

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

You need VBA 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


Gord Dibben MS Excel MVP

On Fri, 12 Jan 2007 09:42:00 -0800, Hpyifur
wrote:

RD - Thanks for your response.

My problem is that it's an area that needs to have information entered into
by other people (and could vary greatly as to the input). It has to be left
justified and is limited on how wide the merged area can be, that's why I was
looking to use the Wrap Text option.

Thanks
-----------------------------

"RagDyer" wrote:

*Unmerge* the cells and then use "Center Across Selection" from:

<Format <Cells. <Alignment tab,
Expand the "Horizontal" window and choose "Center Across Selection".
--
HTH,

RD

---------------------------------------------------------------------------
Please keep all correspondence within the NewsGroup, so all may benefit !
---------------------------------------------------------------------------
"Hpyifur" wrote in message
...
When I merge cells and then choose the wrap text option the Autofit
function
no longer works. Is there a way to get around this without manually
sizing
the row each time?





--

Dave Peterson



Using code in Excel

Merged cells won't Autofit row height
 
How is this code actually used?

"Gord Dibben" wrote:

Long audible sigh here.................

One more victim of "merged cells".

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

You need VBA 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


Gord Dibben MS Excel MVP

On Fri, 12 Jan 2007 09:42:00 -0800, Hpyifur
wrote:

RD - Thanks for your response.

My problem is that it's an area that needs to have information entered into
by other people (and could vary greatly as to the input). It has to be left
justified and is limited on how wide the merged area can be, that's why I was
looking to use the Wrap Text option.

Thanks
-----------------------------

"RagDyer" wrote:

*Unmerge* the cells and then use "Center Across Selection" from:

<Format <Cells. <Alignment tab,
Expand the "Horizontal" window and choose "Center Across Selection".
--
HTH,

RD

---------------------------------------------------------------------------
Please keep all correspondence within the NewsGroup, so all may benefit !
---------------------------------------------------------------------------
"Hpyifur" wrote in message
...
When I merge cells and then choose the wrap text option the Autofit
function
no longer works. Is there a way to get around this without manually
sizing
the row each time?





Gord Dibben

Merged cells won't Autofit row height
 
The code is event code and runs upon entry of text to merged cells.

Right-clcik on the sheet tab and "View Code"

Copy/paste the code into that sheet module.


Gord Dibben MS Excel MVP

On Mon, 1 Oct 2007 15:07:01 -0700, Using code in Excel <Using code in
wrote:

How is this code actually used?

"Gord Dibben" wrote:

Long audible sigh here.................

One more victim of "merged cells".

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

You need VBA 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


Gord Dibben MS Excel MVP

On Fri, 12 Jan 2007 09:42:00 -0800, Hpyifur
wrote:

RD - Thanks for your response.

My problem is that it's an area that needs to have information entered into
by other people (and could vary greatly as to the input). It has to be left
justified and is limited on how wide the merged area can be, that's why I was
looking to use the Wrap Text option.

Thanks
-----------------------------

"RagDyer" wrote:

*Unmerge* the cells and then use "Center Across Selection" from:

<Format <Cells. <Alignment tab,
Expand the "Horizontal" window and choose "Center Across Selection".
--
HTH,

RD

---------------------------------------------------------------------------
Please keep all correspondence within the NewsGroup, so all may benefit !
---------------------------------------------------------------------------
"Hpyifur" wrote in message
...
When I merge cells and then choose the wrap text option the Autofit
function
no longer works. Is there a way to get around this without manually
sizing
the row each time?






Aquarianrep

Merged cells won't Autofit row height
 
This is working perfectly for me, however, I will need to send the
spreadsheets I created to customers. I'd like to get the macro certificate
number, but I don't know how. Any advice?

"Hpyifur" wrote:

When I merge cells and then choose the wrap text option the Autofit function
no longer works. Is there a way to get around this without manually sizing
the row each time?


Jacki

Merged cells won't Autofit row height
 
Gord

I followed the directions but the code doesn't run on text entry. Can you
tell me what I'm doing wrong?

Jacki

"Gord Dibben" wrote:

The code is event code and runs upon entry of text to merged cells.

Right-clcik on the sheet tab and "View Code"

Copy/paste the code into that sheet module.


Gord Dibben MS Excel MVP

On Mon, 1 Oct 2007 15:07:01 -0700, Using code in Excel <Using code in
wrote:

How is this code actually used?

"Gord Dibben" wrote:

Long audible sigh here.................

One more victim of "merged cells".

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

You need VBA 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


Gord Dibben MS Excel MVP

On Fri, 12 Jan 2007 09:42:00 -0800, Hpyifur
wrote:

RD - Thanks for your response.

My problem is that it's an area that needs to have information entered into
by other people (and could vary greatly as to the input). It has to be left
justified and is limited on how wide the merged area can be, that's why I was
looking to use the Wrap Text option.

Thanks
-----------------------------

"RagDyer" wrote:

*Unmerge* the cells and then use "Center Across Selection" from:

<Format <Cells. <Alignment tab,
Expand the "Horizontal" window and choose "Center Across Selection".
--
HTH,

RD

---------------------------------------------------------------------------
Please keep all correspondence within the NewsGroup, so all may benefit !
---------------------------------------------------------------------------
"Hpyifur" wrote in message
...
When I merge cells and then choose the wrap text option the Autofit
function
no longer works. Is there a way to get around this without manually
sizing
the row each time?







Gord Dibben

Merged cells won't Autofit row height
 
From here........no.

Did you copy/paste the code into the appropriate worksheet module?

Do you have "wrap text" enabled on these merged cells?

Maybe events have been disabled.

Run this macro to enable events then use the revised code below to make sure
they get re-enabled on error.

Sub enable_events()
Application.EnableEvents = True
'or just paste the one line to the Immediate window and hit ENTER
End Sub


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
On Error GoTo endit
Application.EnableEvents = False
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
endit:
Application.EnableEvents = True
End Sub


Gord

On Sat, 10 Nov 2007 08:46:02 -0800, Jacki <Jacki @discussions.microsoft.com
wrote:

Gord

I followed the directions but the code doesn't run on text entry. Can you
tell me what I'm doing wrong?

Jacki

"Gord Dibben" wrote:

The code is event code and runs upon entry of text to merged cells.

Right-clcik on the sheet tab and "View Code"

Copy/paste the code into that sheet module.


Gord Dibben MS Excel MVP

On Mon, 1 Oct 2007 15:07:01 -0700, Using code in Excel <Using code in
wrote:

How is this code actually used?

"Gord Dibben" wrote:

Long audible sigh here.................

One more victim of "merged cells".

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

You need VBA 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


Gord Dibben MS Excel MVP

On Fri, 12 Jan 2007 09:42:00 -0800, Hpyifur
wrote:

RD - Thanks for your response.

My problem is that it's an area that needs to have information entered into
by other people (and could vary greatly as to the input). It has to be left
justified and is limited on how wide the merged area can be, that's why I was
looking to use the Wrap Text option.

Thanks
-----------------------------

"RagDyer" wrote:

*Unmerge* the cells and then use "Center Across Selection" from:

<Format <Cells. <Alignment tab,
Expand the "Horizontal" window and choose "Center Across Selection".
--
HTH,

RD

---------------------------------------------------------------------------
Please keep all correspondence within the NewsGroup, so all may benefit !
---------------------------------------------------------------------------
"Hpyifur" wrote in message
...
When I merge cells and then choose the wrap text option the Autofit
function
no longer works. Is there a way to get around this without manually
sizing
the row each time?








PennStan

Merged cells won't Autofit row height
 
Just ran into this problem today. Never thought autoheight would not work
for merged cells since it works for single unmerged cell. Glad I found the
solution here. Macro works fine.

"Aquarianrep" wrote:

This is working perfectly for me, however, I will need to send the
spreadsheets I created to customers. I'd like to get the macro certificate
number, but I don't know how. Any advice?

"Hpyifur" wrote:

When I merge cells and then choose the wrap text option the Autofit function
no longer works. Is there a way to get around this without manually sizing
the row each time?


nanook

Merged cells won't Autofit row height
 
Hi Greg,
I used your code and it worked perfectly...except:
If someone writes text in a cell (which is long enough to wrap and the
height to be adjusted) and then clicks either tab or enter to move to another
cell, a pop-up appears asking for a password in order to unprotect sheet. If
the user then presses escape, without entering a password, and then
tools-protection-unprotect sheet it doesn't ask for the password and just
unprotects!!
I think I must have missed something in the code!
Thanks


"Greg Wilson" wrote:

In place of the word "password" you would hard code your password and remove
the leading apostrophe assuming it's password protected. Otherwise ignore it.
Minimal testing:-

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
Dim ProtectStatus As Boolean

With Target
If .MergeCells And .WrapText Then
ProtectStatus = Me.ProtectContents
If ProtectStatus Then Me.Unprotect ' "password"
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
If ProtectStatus Then Me.Protect ' "password"
End If
End With
End Sub

Regards,
Greg




"Chris" wrote:

Gord
I to used you code, works great, however not if I protected document. Any
suggestions?
--
Regards


"Gord Dibben" wrote:

Long audible sigh here.................

One more victim of "merged cells".

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

You need VBA 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


Gord Dibben MS Excel MVP

On Fri, 12 Jan 2007 09:42:00 -0800, Hpyifur
wrote:

RD - Thanks for your response.

My problem is that it's an area that needs to have information entered into
by other people (and could vary greatly as to the input). It has to be left
justified and is limited on how wide the merged area can be, that's why I was
looking to use the Wrap Text option.

Thanks
-----------------------------

"RagDyer" wrote:

*Unmerge* the cells and then use "Center Across Selection" from:

<Format <Cells. <Alignment tab,
Expand the "Horizontal" window and choose "Center Across Selection".
--
HTH,

RD

---------------------------------------------------------------------------
Please keep all correspondence within the NewsGroup, so all may benefit !
---------------------------------------------------------------------------
"Hpyifur" wrote in message
...
When I merge cells and then choose the wrap text option the Autofit
function
no longer works. Is there a way to get around this without manually
sizing
the row each time?





nanook

Merged cells won't Autofit row height
 
Sorry, I've just spotted my error - I hadn't removed the leading apostrophe
as you said was needed!


"nanook" wrote:

Hi Greg,
I used your code and it worked perfectly...except:
If someone writes text in a cell (which is long enough to wrap and the
height to be adjusted) and then clicks either tab or enter to move to another
cell, a pop-up appears asking for a password in order to unprotect sheet. If
the user then presses escape, without entering a password, and then
tools-protection-unprotect sheet it doesn't ask for the password and just
unprotects!!
I think I must have missed something in the code!
Thanks


"Greg Wilson" wrote:

In place of the word "password" you would hard code your password and remove
the leading apostrophe assuming it's password protected. Otherwise ignore it.
Minimal testing:-

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
Dim ProtectStatus As Boolean

With Target
If .MergeCells And .WrapText Then
ProtectStatus = Me.ProtectContents
If ProtectStatus Then Me.Unprotect ' "password"
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
If ProtectStatus Then Me.Protect ' "password"
End If
End With
End Sub

Regards,
Greg




"Chris" wrote:

Gord
I to used you code, works great, however not if I protected document. Any
suggestions?
--
Regards


"Gord Dibben" wrote:

Long audible sigh here.................

One more victim of "merged cells".

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

You need VBA 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


Gord Dibben MS Excel MVP

On Fri, 12 Jan 2007 09:42:00 -0800, Hpyifur
wrote:

RD - Thanks for your response.

My problem is that it's an area that needs to have information entered into
by other people (and could vary greatly as to the input). It has to be left
justified and is limited on how wide the merged area can be, that's why I was
looking to use the Wrap Text option.

Thanks
-----------------------------

"RagDyer" wrote:

*Unmerge* the cells and then use "Center Across Selection" from:

<Format <Cells. <Alignment tab,
Expand the "Horizontal" window and choose "Center Across Selection".
--
HTH,

RD

---------------------------------------------------------------------------
Please keep all correspondence within the NewsGroup, so all may benefit !
---------------------------------------------------------------------------
"Hpyifur" wrote in message
...
When I merge cells and then choose the wrap text option the Autofit
function
no longer works. Is there a way to get around this without manually
sizing
the row each time?





Lynn

Merged cells won't Autofit row height
 
Way cool!! Thanks!!
--
-Lynn F. PMP


"Gord Dibben" wrote:

The code is event code and runs upon entry of text to merged cells.

Right-clcik on the sheet tab and "View Code"

Copy/paste the code into that sheet module.


Gord Dibben MS Excel MVP

On Mon, 1 Oct 2007 15:07:01 -0700, Using code in Excel <Using code in
wrote:

How is this code actually used?

"Gord Dibben" wrote:

Long audible sigh here.................

One more victim of "merged cells".

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

You need VBA 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


Gord Dibben MS Excel MVP

On Fri, 12 Jan 2007 09:42:00 -0800, Hpyifur
wrote:

RD - Thanks for your response.

My problem is that it's an area that needs to have information entered into
by other people (and could vary greatly as to the input). It has to be left
justified and is limited on how wide the merged area can be, that's why I was
looking to use the Wrap Text option.

Thanks
-----------------------------

"RagDyer" wrote:

*Unmerge* the cells and then use "Center Across Selection" from:

<Format <Cells. <Alignment tab,
Expand the "Horizontal" window and choose "Center Across Selection".
--
HTH,

RD

---------------------------------------------------------------------------
Please keep all correspondence within the NewsGroup, so all may benefit !
---------------------------------------------------------------------------
"Hpyifur" wrote in message
...
When I merge cells and then choose the wrap text option the Autofit
function
no longer works. Is there a way to get around this without manually
sizing
the row each time?







TimS

Merged cells won't Autofit row height
 
Hi, Have loaded this code into the VB area of Excel, but it doesn't run.
Expect that I am missing something, can you please advise how to load it.

Thanks.

"Hpyifur" wrote:

When I merge cells and then choose the wrap text option the Autofit function
no longer works. Is there a way to get around this without manually sizing
the row each time?


TimS

Merged cells won't Autofit row height
 
Just worked out how to do it by right-clicking on sheet tab and "View Code".

"TimS" wrote:

Hi, Have loaded this code into the VB area of Excel, but it doesn't run.
Expect that I am missing something, can you please advise how to load it.

Thanks.

"Hpyifur" wrote:

When I merge cells and then choose the wrap text option the Autofit function
no longer works. Is there a way to get around this without manually sizing
the row each time?


mooresk257

Merged cells won't Autofit row height
 
In Excel 2007, this code also changes the cell property from "unlocked" to
"locked". I think I'll see how I can restructure my sheet to avoid merging
cells.

"Gord Dibben" wrote:

Long audible sigh here.................

One more victim of "merged cells".

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

You need VBA 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


Gord Dibben MS Excel MVP

On Fri, 12 Jan 2007 09:42:00 -0800, Hpyifur
wrote:

RD - Thanks for your response.

My problem is that it's an area that needs to have information entered into
by other people (and could vary greatly as to the input). It has to be left
justified and is limited on how wide the merged area can be, that's why I was
looking to use the Wrap Text option.

Thanks
-----------------------------

"RagDyer" wrote:

*Unmerge* the cells and then use "Center Across Selection" from:

<Format <Cells. <Alignment tab,
Expand the "Horizontal" window and choose "Center Across Selection".
--
HTH,

RD

---------------------------------------------------------------------------
Please keep all correspondence within the NewsGroup, so all may benefit !
---------------------------------------------------------------------------
"Hpyifur" wrote in message
...
When I merge cells and then choose the wrap text option the Autofit
function
no longer works. Is there a way to get around this without manually
sizing
the row each time?





Jeno

Merged cells won't Autofit row height
 
The cell I use the code in locks after i enter text and go to the next cell;
I'm unable to access cell much less re-enter text after I type once and go to
another cell. I'm using excel 2007 and don't use a password when protecting
sheet. After I click "Protect Sheet", click ok without entering password,
enter text into cell, I'm prompted with something about a expanind width, I
click "yes" again, but when I try to go back to cell I can't because it
become locked. How can I protect sheet, use "text wrap in merge cell" code,
enter data, expand merged cells accordingly, not have the cell lock after I
enter text, and be able to re-enter data whenever?

"Greg Wilson" wrote:

In place of the word "password" you would hard code your password and remove
the leading apostrophe assuming it's password protected. Otherwise ignore it.
Minimal testing:-

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
Dim ProtectStatus As Boolean

With Target
If .MergeCells And .WrapText Then
ProtectStatus = Me.ProtectContents
If ProtectStatus Then Me.Unprotect ' "password"
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
If ProtectStatus Then Me.Protect ' "password"
End If
End With
End Sub

Regards,
Greg




"Chris" wrote:

Gord
I to used you code, works great, however not if I protected document. Any
suggestions?
--
Regards


"Gord Dibben" wrote:

Long audible sigh here.................

One more victim of "merged cells".

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

You need VBA 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


Gord Dibben MS Excel MVP

On Fri, 12 Jan 2007 09:42:00 -0800, Hpyifur
wrote:

RD - Thanks for your response.

My problem is that it's an area that needs to have information entered into
by other people (and could vary greatly as to the input). It has to be left
justified and is limited on how wide the merged area can be, that's why I was
looking to use the Wrap Text option.

Thanks
-----------------------------

"RagDyer" wrote:

*Unmerge* the cells and then use "Center Across Selection" from:

<Format <Cells. <Alignment tab,
Expand the "Horizontal" window and choose "Center Across Selection".
--
HTH,

RD

---------------------------------------------------------------------------
Please keep all correspondence within the NewsGroup, so all may benefit !
---------------------------------------------------------------------------
"Hpyifur" wrote in message
...
When I merge cells and then choose the wrap text option the Autofit
function
no longer works. Is there a way to get around this without manually
sizing
the row each time?





[email protected]

Merged cells won't Autofit row height
 
On Tuesday, January 12, 2010 5:01:53 PM UTC-5, Gord Dibben wrote:
The configuation of the merged cells is not your problem.

Works for me with A1:B2 merged.......also A5:D9

Wrap text and row autofit have to be pre-set.

Back to your error message.................

You will receive that particular error message when the worksheet is
protected.

Maybe you want to unprotect then re-protect?

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
On Error GoTo endall
Me.Unprotect Password:="justme"
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
endall:
Me.Protect Password:="justme"
End Sub


Gord


On Mon, 11 Jan 2010 20:38:01 -0800, Tommy-ID
wrote:

Dear Gord Dibben,

Looks very helpfull thanks. Anyway, seems like it only work with merged
cells that merged the on one row (e.g. A1:A2). I try to merge A1:B2 or
multiple row and the error shows: Unable to set the ColumnWidth property of
the Range class. Is there any way to solve this?

Thanks.

Tommy-ID

"Gord Dibben" wrote:

Long audible sigh here.................

One more victim of "merged cells".

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

You need VBA 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


Gord Dibben MS Excel MVP

On Fri, 12 Jan 2007 09:42:00 -0800, Hpyifur
wrote:

RD - Thanks for your response.

My problem is that it's an area that needs to have information entered into
by other people (and could vary greatly as to the input). It has to be left
justified and is limited on how wide the merged area can be, that's why I was
looking to use the Wrap Text option.

Thanks
-----------------------------

"RagDyer" wrote:

*Unmerge* the cells and then use "Center Across Selection" from:

<Format <Cells. <Alignment tab,
Expand the "Horizontal" window and choose "Center Across Selection"..
--
HTH,

RD

---------------------------------------------------------------------------
Please keep all correspondence within the NewsGroup, so all may benefit !
---------------------------------------------------------------------------
"Hpyifur" wrote in message
...
When I merge cells and then choose the wrap text option the Autofit
function
no longer works. Is there a way to get around this without manually
sizing
the row each time?





Gord, it has been a while since you wrote this, but I'm going to shoot this out into the ether in the hopes that it will reach you. Is there any way to make this so that it doesn't empty the undo cache? I understand that the workbook beforeprint event does something like what I'm looking for, but don't know how to change your code so that it works there.

Thank you in advance,
Pat

[email protected]

Merged cells won't Autofit row height
 
On Friday, January 12, 2007 10:38:12 AM UTC-8, Gord Dibben wrote:
Long audible sigh here.................

One more victim of "merged cells".

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

You need VBA 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


Gord Dibben MS Excel MVP

On Fri, 12 Jan 2007 09:42:00 -0800, Hpyifur
wrote:

RD - Thanks for your response.

My problem is that it's an area that needs to have information entered into
by other people (and could vary greatly as to the input). It has to be left
justified and is limited on how wide the merged area can be, that's why I was
looking to use the Wrap Text option.

Thanks
-----------------------------

"RagDyer" wrote:

*Unmerge* the cells and then use "Center Across Selection" from:

<Format <Cells. <Alignment tab,
Expand the "Horizontal" window and choose "Center Across Selection".
--
HTH,

RD

---------------------------------------------------------------------------
Please keep all correspondence within the NewsGroup, so all may benefit !
---------------------------------------------------------------------------
"Hpyifur" wrote in message
...
When I merge cells and then choose the wrap text option the Autofit
function
no longer works. Is there a way to get around this without manually
sizing
the row each time?



Thanks so much for this! Save me on a friday afternoon.

[email protected]

Merged cells won't Autofit row height
 
On Friday, January 12, 2007 at 10:10:01 AM UTC-7, Hpyifur wrote:
When I merge cells and then choose the wrap text option the Autofit function
no longer works. Is there a way to get around this without manually sizing
the row each time?


I know this isn't an answer to your question but I'm looking for an answer as to how to autofit row height in Google Sheets and can't find it ANYWHERE! How do you do that? I can't find it in menus. It's simple in Excel. Thanks, and hope you got an answer to your question!

[email protected]

Merged cells won't Autofit row height
 
On Friday, June 9, 2017 at 4:01:16 PM UTC-4, wrote:
On Friday, January 12, 2007 at 10:10:01 AM UTC-7, Hpyifur wrote:
When I merge cells and then choose the wrap text option the Autofit function
no longer works. Is there a way to get around this without manually sizing
the row each time?


I know this isn't an answer to your question but I'm looking for an answer as to how to autofit row height in Google Sheets and can't find it ANYWHERE! How do you do that? I can't find it in menus. It's simple in Excel. Thanks, and hope you got an answer to your question!


Hi! I know this is an old forum, but did you ever find the code? I'm also looking for it! Thank you!


All times are GMT +1. The time now is 09:02 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com