A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Autosize cells as data is entered



 
 
Thread Tools Display Modes
  #1  
Old February 22nd, 2007, 06:49 PM posted to microsoft.public.excel.misc
Carol
external usenet poster
 
Posts: 401
Default Autosize cells as data is entered

Hello.

I have my cells set to Wrap & the row is set to Auto-Fit. The "Number" is
set to General.

When I add text, it wraps, however, the cell-size is not changing! What do
I have to do to get the cell (or row height) to grow as text is added?

--
Carol
  #2  
Old February 22nd, 2007, 07:30 PM posted to microsoft.public.excel.misc
Gord Dibben
external usenet poster
 
Posts: 20,252
Default Autosize cells as data is entered

I'm betting you have some "merged cells" which won't Autofit without VBA code.

If this is the case and you're interested in the code, post back.


Gord Dibben MS Excel MVP

On Thu, 22 Feb 2007 10:49:13 -0800, Carol
wrote:

Hello.

I have my cells set to Wrap & the row is set to Auto-Fit. The "Number" is
set to General.

When I add text, it wraps, however, the cell-size is not changing! What do
I have to do to get the cell (or row height) to grow as text is added?


  #3  
Old February 22nd, 2007, 07:38 PM posted to microsoft.public.excel.misc
Carol
external usenet poster
 
Posts: 401
Default Autosize cells as data is entered

Nevermind! Just realized my cells are merged - therefore, none of the
solutions I was trying will work.
--
Carol


"Carol" wrote:

Hello.

I have my cells set to Wrap & the row is set to Auto-Fit. The "Number" is
set to General.

When I add text, it wraps, however, the cell-size is not changing! What do
I have to do to get the cell (or row height) to grow as text is added?

--
Carol

  #4  
Old February 22nd, 2007, 07:42 PM posted to microsoft.public.excel.misc
Carol
external usenet poster
 
Posts: 401
Default Autosize cells as data is entered

It is the case! I think we were both responding to my post at the same
time.. I would love the VBA code - though a novice at that. HOWEVER - if
it's easier than completely re-doing my form, I'll be happy to take a stab at
it!

Thank you Gord!
--
Carol


"Gord Dibben" wrote:

I'm betting you have some "merged cells" which won't Autofit without VBA code.

If this is the case and you're interested in the code, post back.


Gord Dibben MS Excel MVP

On Thu, 22 Feb 2007 10:49:13 -0800, Carol
wrote:

Hello.

I have my cells set to Wrap & the row is set to Auto-Fit. The "Number" is
set to General.

When I add text, it wraps, however, the cell-size is not changing! What do
I have to do to get the cell (or row height) to grow as text is added?



  #5  
Old February 22nd, 2007, 08:05 PM posted to microsoft.public.excel.misc
Gord Dibben
external usenet poster
 
Posts: 20,252
Default Autosize cells as data is entered

I avoid meged cells like the plague simply due to the many problems caused by
these.

But............................

Here is event code from Greg Wilson.

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

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

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

Copy/paste the above into that sheet module.

As you enter data the rows will autofit.


Gord

On Thu, 22 Feb 2007 11:42:45 -0800, Carol
wrote:

It is the case! I think we were both responding to my post at the same
time.. I would love the VBA code - though a novice at that. HOWEVER - if
it's easier than completely re-doing my form, I'll be happy to take a stab at
it!

Thank you Gord!


  #6  
Old February 22nd, 2007, 09:50 PM posted to microsoft.public.excel.misc
Carol
external usenet poster
 
Posts: 401
Default Autosize cells as data is entered

You (and Greg Wilson)...... BRILLIANT! Worked beautifully!

Thank you for help - and perfect instruction!
--
Carol


"Gord Dibben" wrote:

I avoid meged cells like the plague simply due to the many problems caused by
these.

But............................

Here is event code from Greg Wilson.

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

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

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

Copy/paste the above into that sheet module.

As you enter data the rows will autofit.


Gord

On Thu, 22 Feb 2007 11:42:45 -0800, Carol
wrote:

It is the case! I think we were both responding to my post at the same
time.. I would love the VBA code - though a novice at that. HOWEVER - if
it's easier than completely re-doing my form, I'll be happy to take a stab at
it!

Thank you Gord!



  #7  
Old July 14th, 2008, 10:29 PM posted to microsoft.public.excel.misc
DoubleZ
external usenet poster
 
Posts: 43
Default Autosize cells as data is entered

Hey Gord,

I have a similar problem to the one you addressed in your post. When I
highlight all the rows then select 'format', 'AutoFit Row Height' it will
make the adjustments. However, once new text is added (actually, eveything
in this tab is being controlled by a formula) the rows do not change height
to accomodate the new text. I do have a couple merged cells, but they are at
the very top and are not part of the rows that I am trying to use AutoFit on.
I inserted the VBA code you pasted just in case I have merged cells, but
that didn't help. This is the only other unique thing I can think of that
may be causing it: in the cells of one column I have the values of multiple
texts being returned on separate lines (e.g. one of the cells has the formula
K14&CHAR(10)&L14&CHAR(10)&M14&CHAR(10)&N14).

Can you think of any reason why AutoFit wont work?

"Gord Dibben" wrote:

I avoid meged cells like the plague simply due to the many problems caused by
these.

But............................

Here is event code from Greg Wilson.

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

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

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

Copy/paste the above into that sheet module.

As you enter data the rows will autofit.


Gord

On Thu, 22 Feb 2007 11:42:45 -0800, Carol
wrote:

It is the case! I think we were both responding to my post at the same
time.. I would love the VBA code - though a novice at that. HOWEVER - if
it's easier than completely re-doing my form, I'll be happy to take a stab at
it!

Thank you Gord!



  #8  
Old July 15th, 2008, 02:15 AM posted to microsoft.public.excel.misc
Gord Dibben
external usenet poster
 
Posts: 20,252
Default Autosize cells as data is entered

Even without merged cells Excel doen't seem to like too many linefeeds and will
not autofit after a certain point.

I tried your example formula in A14 with row set to Autofit.

Entry of text in K14 and L14 autofit but entries in M14 and N14 did not increase
row height.

I don't know of a workaround.


Gord Dibben MS Excel MVP

On Mon, 14 Jul 2008 14:29:01 -0700, DoubleZ
wrote:

Hey Gord,

I have a similar problem to the one you addressed in your post. When I
highlight all the rows then select 'format', 'AutoFit Row Height' it will
make the adjustments. However, once new text is added (actually, eveything
in this tab is being controlled by a formula) the rows do not change height
to accomodate the new text. I do have a couple merged cells, but they are at
the very top and are not part of the rows that I am trying to use AutoFit on.
I inserted the VBA code you pasted just in case I have merged cells, but
that didn't help. This is the only other unique thing I can think of that
may be causing it: in the cells of one column I have the values of multiple
texts being returned on separate lines (e.g. one of the cells has the formula
K14&CHAR(10)&L14&CHAR(10)&M14&CHAR(10)&N14).

Can you think of any reason why AutoFit wont work?

"Gord Dibben" wrote:

I avoid meged cells like the plague simply due to the many problems caused by
these.

But............................

Here is event code from Greg Wilson.

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

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

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

Copy/paste the above into that sheet module.

As you enter data the rows will autofit.


Gord

On Thu, 22 Feb 2007 11:42:45 -0800, Carol
wrote:

It is the case! I think we were both responding to my post at the same
time.. I would love the VBA code - though a novice at that. HOWEVER - if
it's easier than completely re-doing my form, I'll be happy to take a stab at
it!

Thank you Gord!




  #9  
Old October 16th, 2008, 12:35 AM posted to microsoft.public.excel.misc
Brian
external usenet poster
 
Posts: 1,396
Default Autosize cells as data is entered

Does anyone know how to modify this code so that it will work in a protected
sheet?

"Gord Dibben" wrote:

I avoid meged cells like the plague simply due to the many problems caused by
these.

But............................

Here is event code from Greg Wilson.

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

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

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

Copy/paste the above into that sheet module.

As you enter data the rows will autofit.


Gord

On Thu, 22 Feb 2007 11:42:45 -0800, Carol
wrote:

It is the case! I think we were both responding to my post at the same
time.. I would love the VBA code - though a novice at that. HOWEVER - if
it's easier than completely re-doing my form, I'll be happy to take a stab at
it!

Thank you Gord!



  #10  
Old October 16th, 2008, 03:33 AM posted to microsoft.public.excel.misc
Gord Dibben
external usenet poster
 
Posts: 20,252
Default Autosize cells as data is entered

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
On Error GoTo endit
Application.EnableEvents = False
With Target
If .MergeCells And .WrapText Then
ActiveSheet.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
endit:
Application.EnableEvents = True
ActiveSheet.Protect Password:="justme"
End Sub


Gord

On Wed, 15 Oct 2008 16:35:03 -0700, Brian
wrote:

Does anyone know how to modify this code so that it will work in a protected
sheet?

"Gord Dibben" wrote:

I avoid meged cells like the plague simply due to the many problems caused by
these.

But............................

Here is event code from Greg Wilson.

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

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

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

Copy/paste the above into that sheet module.

As you enter data the rows will autofit.


Gord

On Thu, 22 Feb 2007 11:42:45 -0800, Carol
wrote:

It is the case! I think we were both responding to my post at the same
time.. I would love the VBA code - though a novice at that. HOWEVER - if
it's easier than completely re-doing my form, I'll be happy to take a stab at
it!

Thank you Gord!




 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 06:44 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.