(Msg. 17) Posted: Tue Jul 28, 2009 10:04 am
Post subject: Re: where text wraps in a cell, how can the row height be auto set [Login to view extended thread Info.] Archived from groups: microsoft>public>excel>worksheet>functions (more info?)
Make appropriate changes to the range in Greg's code.
Wrap Text row>autofit must be enabled to start with.
If stuck, please post details of your merged cells area(s)
Gord Dibben MS Excel MVP
On Mon, 27 Jul 2009 12:01:02 -0700, Linda B
<LindaB.DeleteThis@discussions.microsoft.com> wrote:
>
>I have a row with merged cells and I am trying to get the height to
>automatically adjust. How do I get this to happen?
>Linda B.
>
>"Greg Wilson" wrote:
>
>> Paste the following to the worksheet's code module. The code assumes that
>> each cell within A1:A10 is merged to adjacent columns as opposed to these
>> cells being merged - e.g. A1:D1 are merged, A2:D2 are merged, A3:D3 are
>> merged etc. Change the range reference to suit. Can be a single cell.
>>
>> Private Sub Worksheet_Change(ByVal Target As Range)
>> Dim NewRwHt As Single
>> Dim cWdth As Single, MrgeWdth As Single
>> Dim r As Range, c As Range, cc As Range
>> Dim ma As Range
>>
>> Set r = Range("A1:A10")
>> If Not Intersect(Target, r) Is Nothing 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 Sub
>>
>> Alternatively, size the column width of a single cell in the same row to the
>> combined column widths of the merged range. Format the font, wraptext and
>> alignment exactly the same except change the font colour to be the same as
>> the background (to hide it). Enter a formula that references the active cell
>> of the merged range (e.g. "=C10"). Use the worksheet_change event to force
>> autofit of this cell. The merged cell range will then autofit along with it.
>> This assumes it is columns that are merged. Use the same logic if rows are
>> merged.
>>
>> Regards,
>> Greg
>>
>>
>>
>>
>> "Stephen Sandor" wrote:
>>
>> > I have merged a number of cells and included text that wraps in the cell. Is
>> > it possible to set the cell so that the height is automatically adjusted to
>> > the height of the text?
(Msg. 18) Posted: Tue Sep 29, 2009 11:19 am
Post subject: Re: where text wraps in a cell, how can the row height be auto set [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
HELP! Just need to have rows auto fit contents (expand). Do not understand
the complicated code referenced in this post or even where to copy and insert
this code. Why doesn't the "Auto fit Row Height" option work under
formatting?
"Gord Dibben" wrote:
> Make appropriate changes to the range in Greg's code.
>
> Wrap Text row>autofit must be enabled to start with.
>
> If stuck, please post details of your merged cells area(s)
>
>
>
> Gord Dibben MS Excel MVP
>
>
> On Mon, 27 Jul 2009 12:01:02 -0700, Linda B
> <LindaB DeleteThis @discussions.microsoft.com> wrote:
>
> >
> >I have a row with merged cells and I am trying to get the height to
> >automatically adjust. How do I get this to happen?
> >Linda B.
> >
> >"Greg Wilson" wrote:
> >
> >> Paste the following to the worksheet's code module. The code assumes that
> >> each cell within A1:A10 is merged to adjacent columns as opposed to these
> >> cells being merged - e.g. A1:D1 are merged, A2:D2 are merged, A3:D3 are
> >> merged etc. Change the range reference to suit. Can be a single cell.
> >>
> >> Private Sub Worksheet_Change(ByVal Target As Range)
> >> Dim NewRwHt As Single
> >> Dim cWdth As Single, MrgeWdth As Single
> >> Dim r As Range, c As Range, cc As Range
> >> Dim ma As Range
> >>
> >> Set r = Range("A1:A10")
> >> If Not Intersect(Target, r) Is Nothing 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 Sub
> >>
> >> Alternatively, size the column width of a single cell in the same row to the
> >> combined column widths of the merged range. Format the font, wraptext and
> >> alignment exactly the same except change the font colour to be the same as
> >> the background (to hide it). Enter a formula that references the active cell
> >> of the merged range (e.g. "=C10"). Use the worksheet_change event to force
> >> autofit of this cell. The merged cell range will then autofit along with it.
> >> This assumes it is columns that are merged. Use the same logic if rows are
> >> merged.
> >>
> >> Regards,
> >> Greg
> >>
> >>
> >>
> >>
> >> "Stephen Sandor" wrote:
> >>
> >> > I have merged a number of cells and included text that wraps in the cell. Is
> >> > it possible to set the cell so that the height is automatically adjusted to
> >> > the height of the text?
>
>
(Msg. 19) Posted: Tue Sep 29, 2009 11:28 am
Post subject: Re: where text wraps in a cell, how can the row height be auto set [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
More info: I'm using Excel 2007 - several columns are merged and merged and
text wrap boxes are checked.
"Redwren" wrote:
> HELP! Just need to have rows auto fit contents (expand). Do not understand
> the complicated code referenced in this post or even where to copy and insert
> this code. Why doesn't the "Auto fit Row Height" option work under
> formatting?
>
> "Gord Dibben" wrote:
>
> > Make appropriate changes to the range in Greg's code.
> >
> > Wrap Text row>autofit must be enabled to start with.
> >
> > If stuck, please post details of your merged cells area(s)
> >
> >
> >
> > Gord Dibben MS Excel MVP
> >
> >
> > On Mon, 27 Jul 2009 12:01:02 -0700, Linda B
> > <LindaB.DeleteThis@discussions.microsoft.com> wrote:
> >
> > >
> > >I have a row with merged cells and I am trying to get the height to
> > >automatically adjust. How do I get this to happen?
> > >Linda B.
> > >
> > >"Greg Wilson" wrote:
> > >
> > >> Paste the following to the worksheet's code module. The code assumes that
> > >> each cell within A1:A10 is merged to adjacent columns as opposed to these
> > >> cells being merged - e.g. A1:D1 are merged, A2:D2 are merged, A3:D3 are
> > >> merged etc. Change the range reference to suit. Can be a single cell.
> > >>
> > >> Private Sub Worksheet_Change(ByVal Target As Range)
> > >> Dim NewRwHt As Single
> > >> Dim cWdth As Single, MrgeWdth As Single
> > >> Dim r As Range, c As Range, cc As Range
> > >> Dim ma As Range
> > >>
> > >> Set r = Range("A1:A10")
> > >> If Not Intersect(Target, r) Is Nothing 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 Sub
> > >>
> > >> Alternatively, size the column width of a single cell in the same row to the
> > >> combined column widths of the merged range. Format the font, wraptext and
> > >> alignment exactly the same except change the font colour to be the same as
> > >> the background (to hide it). Enter a formula that references the active cell
> > >> of the merged range (e.g. "=C10"). Use the worksheet_change event to force
> > >> autofit of this cell. The merged cell range will then autofit along with it.
> > >> This assumes it is columns that are merged. Use the same logic if rows are
> > >> merged.
> > >>
> > >> Regards,
> > >> Greg
> > >>
> > >>
> > >>
> > >>
> > >> "Stephen Sandor" wrote:
> > >>
> > >> > I have merged a number of cells and included text that wraps in the cell. Is
> > >> > it possible to set the cell so that the height is automatically adjusted to
> > >> > the height of the text?
> >
> >
(Msg. 20) Posted: Tue Sep 29, 2009 12:33 pm
Post subject: Re: where text wraps in a cell, how can the row height be auto set [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
Plain and simple...................If you have merged cells in the range,
Autofit won't work even with wraptext enabled.
You will need the code if you insist upon using merged cells.
The developers added the merge cells feature in Excel 97 without thinking
about row autofit functionality.
Have not bothered to correct since.
Gord
On Tue, 29 Sep 2009 11:19:01 -0700, Redwren
<Redwren.RemoveThis@discussions.microsoft.com> wrote:
>HELP! Just need to have rows auto fit contents (expand). Do not understand
>the complicated code referenced in this post or even where to copy and insert
>this code. Why doesn't the "Auto fit Row Height" option work under
>formatting?
>
>"Gord Dibben" wrote:
>
>> Make appropriate changes to the range in Greg's code.
>>
>> Wrap Text row>autofit must be enabled to start with.
>>
>> If stuck, please post details of your merged cells area(s)
>>
>>
>>
>> Gord Dibben MS Excel MVP
>>
>>
>> On Mon, 27 Jul 2009 12:01:02 -0700, Linda B
>> <LindaB.RemoveThis@discussions.microsoft.com> wrote:
>>
>> >
>> >I have a row with merged cells and I am trying to get the height to
>> >automatically adjust. How do I get this to happen?
>> >Linda B.
>> >
>> >"Greg Wilson" wrote:
>> >
>> >> Paste the following to the worksheet's code module. The code assumes that
>> >> each cell within A1:A10 is merged to adjacent columns as opposed to these
>> >> cells being merged - e.g. A1:D1 are merged, A2:D2 are merged, A3:D3 are
>> >> merged etc. Change the range reference to suit. Can be a single cell.
>> >>
>> >> Private Sub Worksheet_Change(ByVal Target As Range)
>> >> Dim NewRwHt As Single
>> >> Dim cWdth As Single, MrgeWdth As Single
>> >> Dim r As Range, c As Range, cc As Range
>> >> Dim ma As Range
>> >>
>> >> Set r = Range("A1:A10")
>> >> If Not Intersect(Target, r) Is Nothing 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 Sub
>> >>
>> >> Alternatively, size the column width of a single cell in the same row to the
>> >> combined column widths of the merged range. Format the font, wraptext and
>> >> alignment exactly the same except change the font colour to be the same as
>> >> the background (to hide it). Enter a formula that references the active cell
>> >> of the merged range (e.g. "=C10"). Use the worksheet_change event to force
>> >> autofit of this cell. The merged cell range will then autofit along with it.
>> >> This assumes it is columns that are merged. Use the same logic if rows are
>> >> merged.
>> >>
>> >> Regards,
>> >> Greg
>> >>
>> >>
>> >>
>> >>
>> >> "Stephen Sandor" wrote:
>> >>
>> >> > I have merged a number of cells and included text that wraps in the cell. Is
>> >> > it possible to set the cell so that the height is automatically adjusted to
>> >> > the height of the text?
>>
>>
(Msg. 21) Posted: Fri Nov 06, 2009 8:23 am
Post subject: Re: where text wraps in a cell, how can the row height be auto set [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
"Gord Dibben" wrote:
> Plain and simple...................If you have merged cells in the range,
> Autofit won't work even with wraptext enabled.
>
> You will need the code if you insist upon using merged cells.
>
> The developers added the merge cells feature in Excel 97 without thinking
> about row autofit functionality.
>
> Have not bothered to correct since.
>
>
> Gord
>
>
> On Tue, 29 Sep 2009 11:19:01 -0700, Redwren
> <Redwren.TakeThisOut@discussions.microsoft.com> wrote:
>
> >HELP! Just need to have rows auto fit contents (expand). Do not understand
> >the complicated code referenced in this post or even where to copy and insert
> >this code. Why doesn't the "Auto fit Row Height" option work under
> >formatting?
> >
> >"Gord Dibben" wrote:
> >
> >> Make appropriate changes to the range in Greg's code.
> >>
> >> Wrap Text row>autofit must be enabled to start with.
> >>
> >> If stuck, please post details of your merged cells area(s)
> >>
> >>
> >>
> >> Gord Dibben MS Excel MVP
> >>
> >>
> >> On Mon, 27 Jul 2009 12:01:02 -0700, Linda B
> >> <LindaB.TakeThisOut@discussions.microsoft.com> wrote:
> >>
> >> >
> >> >I have a row with merged cells and I am trying to get the height to
> >> >automatically adjust. How do I get this to happen?
> >> >Linda B.
> >> >
> >> >"Greg Wilson" wrote:
> >> >
> >> >> Paste the following to the worksheet's code module. The code assumes that
> >> >> each cell within A1:A10 is merged to adjacent columns as opposed to these
> >> >> cells being merged - e.g. A1:D1 are merged, A2:D2 are merged, A3:D3 are
> >> >> merged etc. Change the range reference to suit. Can be a single cell.
> >> >>
> >> >> Private Sub Worksheet_Change(ByVal Target As Range)
> >> >> Dim NewRwHt As Single
> >> >> Dim cWdth As Single, MrgeWdth As Single
> >> >> Dim r As Range, c As Range, cc As Range
> >> >> Dim ma As Range
> >> >>
> >> >> Set r = Range("A1:A10")
> >> >> If Not Intersect(Target, r) Is Nothing 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 Sub
> >> >>
> >> >> Alternatively, size the column width of a single cell in the same row to the
> >> >> combined column widths of the merged range. Format the font, wraptext and
> >> >> alignment exactly the same except change the font colour to be the same as
> >> >> the background (to hide it). Enter a formula that references the active cell
> >> >> of the merged range (e.g. "=C10"). Use the worksheet_change event to force
> >> >> autofit of this cell. The merged cell range will then autofit along with it.
> >> >> This assumes it is columns that are merged. Use the same logic if rows are
> >> >> merged.
> >> >>
> >> >> Regards,
> >> >> Greg
> >> >>
> >> >>
> >> >>
> >> >>
> >> >> "Stephen Sandor" wrote:
> >> >>
> >> >> > I have merged a number of cells and included text that wraps in the cell. Is
> >> >> > it possible to set the cell so that the height is automatically adjusted to
> >> >> > the height of the text?
> >>
> >>
> I have carefully read through this discussion twice and I am no better off than when I started. There are obviously some very clever people trying their best to resolve a very simple problem. But clearly without success, as the same user problem is repeated many times. So to the basics.
Admit it, auto fit row height for a merged and wrapped cell (eg cells B5 to
J5) containing an unknown (and variable) number of charaters does not work,
has never worked.
Also, microsoft has known about this since 1997 or earlier.
As this is a pretty much basic function, microsoft must explain why it has
not been fixed.
It is all very well for the clever people to provide macro answers, but most
users do not know and do not use macros. So there has to be a better way that
the ordinary user can easily implement.
Notwithstanding the above, I am a low level macro user and the code provided
above baffles me. (MS Excel 2007)
All times are: Eastern Time (US & Canada) (change) Goto page Previous1, 2, 3
Page 3 of 3
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum