View Single Post
  #15   Report Post  
Posted to microsoft.public.excel.misc
donna-LexusWebs donna-LexusWebs is offline
external usenet poster
 
Posts: 6
Default Autosize cells as data is entered

I added the VBA to an existing worksheet and although it didn't expand my
rows as soon as I added the code, as soon as I typed into the cell again the
row expanded and stayed expanded. I hope that helps!

Thanks for the code - and the specific instructions where to add it (rt-clk
on the tab). I never knew that and always wondered how code was being added!!

Thanks again!

"Gord Dibben" wrote:

Only works when entering new data or editing existing data.


Gord



On Mon, 8 Jun 2009 10:45:01 -0700, brianna3
wrote:

will this work for data that has already been entered into my sheet or will
this only work on a new sheet and any data entered after it is applied?

"Gord Dibben" wrote:

Good to hear

Thanks for the feedback

On Thu, 16 Oct 2008 06:31:01 -0700, Brian
wrote:

Thank you, Gord!

Note that I did have a slight issue where the resized cells were becoming
locked after editing, but I stole a line of code (ma.Locked = False) from
another post, and that seems to solve the issue.

Thanks again.


"Gord Dibben" wrote:

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