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!
|