|
|
| Next: Using 2 IF statements for the same cell |
| Author |
Message |
Hpyifur External

Since: Jan 12, 2007 Posts: 2
|
Posted: Fri Jan 12, 2007 9:10 am Post subject: Merged cells won't Autofit row height Archived from groups: microsoft>public>excel>misc (more info?) |
|
|
|
| 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?
|
|
|
| Back to top |
|
 |
RagDyer External

Since: Jun 14, 2004 Posts: 762
|
Posted: Fri Jan 12, 2007 9:24 am Post subject: Re: Merged cells won't Autofit row height [Login to view extended thread Info.] Archived from groups: per prev. post (more info?) |
|
|
*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" <Hpyifur.DeleteThis@discussions.microsoft.com> wrote in message
news:0518FECC-94CC-40B2-ACEF-1919895A5399@microsoft.com...
> 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? |
|
| Back to top |
|
 |
Hpyifur External

Since: Jan 12, 2007 Posts: 2
|
Posted: Fri Jan 12, 2007 9:42 am Post subject: Re: Merged cells won't Autofit row height [Login to view extended thread Info.] Archived from groups: per prev. post (more info?) |
|
|
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" <Hpyifur RemoveThis @discussions.microsoft.com> wrote in message
> news:0518FECC-94CC-40B2-ACEF-1919895A5399@microsoft.com...
> > 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?
>
> |
|
| Back to top |
|
 |
Gord Dibben External

Since: Feb 23, 2004 Posts: 9178
|
Posted: Fri Jan 12, 2007 10:38 am Post subject: Re: Merged cells won't Autofit row height [Login to view extended thread Info.] Archived from groups: per prev. post (more info?) |
|
|
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 <Hpyifur RemoveThis @discussions.microsoft.com>
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" <Hpyifur RemoveThis @discussions.microsoft.com> wrote in message
>> news:0518FECC-94CC-40B2-ACEF-1919895A5399@microsoft.com...
>> > 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?
>>
>> |
|
| Back to top |
|
 |
Chris External

Since: Apr 10, 2006 Posts: 390
|
Posted: Sun Mar 04, 2007 10:20 pm Post subject: Re: Merged cells won't Autofit row height [Login to view extended thread Info.] Archived from groups: per prev. post (more info?) |
|
|
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 <Hpyifur DeleteThis @discussions.microsoft.com>
> 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" <Hpyifur DeleteThis @discussions.microsoft.com> wrote in message
> >> news:0518FECC-94CC-40B2-ACEF-1919895A5399@microsoft.com...
> >> > 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?
> >>
> >>
>
> |
|
| Back to top |
|
 |
Greg Wilson External

Since: Apr 16, 2006 Posts: 89
|
Posted: Sun Mar 04, 2007 11:16 pm Post subject: Re: Merged cells won't Autofit row height [Login to view extended thread Info.] Archived from groups: per prev. post (more info?) |
|
|
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 <Hpyifur DeleteThis @discussions.microsoft.com>
> > 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" <Hpyifur DeleteThis @discussions.microsoft.com> wrote in message
> > >> news:0518FECC-94CC-40B2-ACEF-1919895A5399@microsoft.com...
> > >> > 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?
> > >>
> > >>
> >
> > |
|
| Back to top |
|
 |
Odie External

Since: Mar 01, 2007 Posts: 5
|
Posted: Thu Jun 28, 2007 8:02 am Post subject: Re: Merged cells won't Autofit row height [Login to view extended thread Info.] Archived from groups: per prev. post (more info?) |
|
|
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 <Hpyifur.DeleteThis@discussions.microsoft.com>
> 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" <Hpyifur.DeleteThis@discussions.microsoft.com> wrote in message
> >> news:0518FECC-94CC-40B2-ACEF-1919895A5399@microsoft.com...
> >> > 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?
> >>
> >>
>
> |
|
| Back to top |
|
 |
Dave Peterson External

Since: Jul 08, 2005 Posts: 16049
|
Posted: Thu Jun 28, 2007 10:26 am Post subject: Re: Merged cells won't Autofit row height [Login to view extended thread Info.] Archived from groups: per prev. post (more info?) |
|
|
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 <Hpyifur.RemoveThis@discussions.microsoft.com>
> > 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" <Hpyifur.RemoveThis@discussions.microsoft.com> wrote in message
> > >> news:0518FECC-94CC-40B2-ACEF-1919895A5399@microsoft.com...
> > >> > 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 |
|
| Back to top |
|
 |
Odie External

Since: Mar 01, 2007 Posts: 5
|
Posted: Thu Jun 28, 2007 10:26 am Post subject: Re: Merged cells won't Autofit row height [Login to view extended thread Info.] Archived from groups: per prev. post (more info?) |
|
|
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 <Hpyifur DeleteThis @discussions.microsoft.com>
> > > 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" <Hpyifur DeleteThis @discussions.microsoft.com> wrote in message
> > > >> news:0518FECC-94CC-40B2-ACEF-1919895A5399@microsoft.com...
> > > >> > 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
> |
|
| Back to top |
|
 |
Gord Dibben External

Since: Feb 23, 2004 Posts: 9178
|
Posted: Thu Jun 28, 2007 10:26 am Post subject: Re: Merged cells won't Autofit row height [Login to view extended thread Info.] Archived from groups: per prev. post (more info?) |
|
|
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 <Odie DeleteThis @discussions.microsoft.com> 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 <Hpyifur DeleteThis @discussions.microsoft.com>
>> > > 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" <Hpyifur DeleteThis @discussions.microsoft.com> wrote in message
>> > > >> news:0518FECC-94CC-40B2-ACEF-1919895A5399@microsoft.com...
>> > > >> > 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
>> |
|
| Back to top |
|
 |
bf

Joined: Oct 25, 2007 Posts: 1
|
Posted: Thu Oct 25, 2007 11:34 am Post subject: Worksheet code [Login to view extended thread Info.] |
|
|
Thanks for the info on the code. I am having trouble to get the code to work properly, any ideas? I pasted it into the worksheet where I need the autofit code to work, but with no success.
What triggers the code to work? The merging of the cells, the autofit process??? |
|
| Back to top |
|
 |
mooresk257 External

Since: May 03, 2009 Posts: 1
|
Posted: Sun May 03, 2009 3:16 pm Post subject: Re: Merged cells won't Autofit row height [Login to view extended thread Info.] Archived from groups: microsoft>public>excel>misc (more info?) |
|
|
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 <Hpyifur.RemoveThis@discussions.microsoft.com>
> 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" <Hpyifur.RemoveThis@discussions.microsoft.com> wrote in message
> >> news:0518FECC-94CC-40B2-ACEF-1919895A5399@microsoft.com...
> >> > 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?
> >>
> >>
>
> |
|
| Back to top |
|
 |
Jeno External

Since: Dec 29, 2006 Posts: 3
|
Posted: Mon Jul 20, 2009 2:43 pm Post subject: Re: Merged cells won't Autofit row height [Login to view extended thread Info.] Archived from groups: per prev. post (more info?) |
|
|
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 <Hpyifur RemoveThis @discussions.microsoft.com>
> > > 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" <Hpyifur RemoveThis @discussions.microsoft.com> wrote in message
> > > >> news:0518FECC-94CC-40B2-ACEF-1919895A5399@microsoft.com...
> > > >> > 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?
> > > >>
> > > >>
> > >
> > > |
|
| Back to top |
|
 |
ELizzy010 External

Since: Sep 17, 2009 Posts: 1
|
Posted: Thu Sep 17, 2009 11:23 am Post subject: Re: Merged cells won't Autofit row height [Login to view extended thread Info.] Archived from groups: per prev. post (more info?) |
|
|
I am new to Visual Basic.
I pasted the code into the box that appeared when I selected "View Code."
However, when I returned to the Worksheet I still could not autofit (either
by double-clicking the row or by selecting "Autofit").
How may I activate the code?
I tried (1) "Save" and (2) "Run" ... which created a Macro that runs when I
open the document but I cannot locate the Macro to use / delete it.
The Procedure is currently set to "Change." I wondered if that was a
problem since this is "Event" activated ...
Thank you for your patience!
Erin
"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
> Excel.DeleteThis@discussions.microsoft.com> 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 <Hpyifur.DeleteThis@discussions.microsoft.com>
> >> 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" <Hpyifur.DeleteThis@discussions.microsoft.com> wrote in message
> >> >> news:0518FECC-94CC-40B2-ACEF-1919895A5399@microsoft.com...
> >> >> > 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?
> >> >>
> >> >>
> >>
> >>
>
> |
|
| Back to top |
|
 |
Gord Dibben External

Since: Feb 23, 2004 Posts: 9178
|
Posted: Thu Sep 17, 2009 2:23 pm Post subject: Re: Merged cells won't Autofit row height [Login to view extended thread Info.] Archived from groups: per prev. post (more info?) |
|
|
When you right-click on the sheet tab and "View Code" a sheet module(not a
"box") will open.
Paste the code into that module.
The rows must be preset to WrapText and Autofit.
You do not "run" the code nor do you double-click on a row
The "change" event takes place when you type something into a merged cell
and hit the ENTER key.
At that point the code is "activated" and your row expands to fit.
Gord
On Thu, 17 Sep 2009 11:23:16 -0700, ELizzy010
<ELizzy010.RemoveThis@discussions.microsoft.com> wrote:
>I am new to Visual Basic.
>
>I pasted the code into the box that appeared when I selected "View Code."
>However, when I returned to the Worksheet I still could not autofit (either
>by double-clicking the row or by selecting "Autofit").
>
>How may I activate the code?
>
>I tried (1) "Save" and (2) "Run" ... which created a Macro that runs when I
>open the document but I cannot locate the Macro to use / delete it.
>
>The Procedure is currently set to "Change." I wondered if that was a
>problem since this is "Event" activated ...
>
>Thank you for your patience!
>Erin
>
>"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
>> Excel.RemoveThis@discussions.microsoft.com> 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 <Hpyifur.RemoveThis@discussions.microsoft.com>
>> >> 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" <Hpyifur.RemoveThis@discussions.microsoft.com> wrote in message
>> >> >> news:0518FECC-94CC-40B2-ACEF-1919895A5399@microsoft.com...
>> >> >> > 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?
>> >> >>
>> >> >>
>> >>
>> >>
>>
>> |
|
| Back to top |
|
 |
leigo

Joined: Nov 04, 2009 Posts: 1
|
Posted: Wed Nov 04, 2009 3:41 pm Post subject: VB code poses problem for undo feature [Login to view extended thread Info.] |
|
|
The code posted by Gord Dibben is great for solving the row height autofit problem in merged cells, but I have found that once the code is in place I am no longer able to use the undo feature on the affected cells.
Does anyone have a solution to this problem?
Thanks |
|
| Back to top |
|
 |
amber01

Joined: Nov 23, 2009 Posts: 1
|
Posted: Mon Nov 23, 2009 1:18 pm Post subject: [Login to view extended thread Info.] |
|
|
Hi,
When you protect your worksheet there are some options to allow for the user. One of the options is to format rows. So you can autofit rows when protecting your sheet. |
|
| Back to top |
|
 |
|
|
|
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
|
| |
|
|