Hi,
Although this code works with cells where data is actually in it, I need it to work where the cell contains text that has been linked from another sheet.
Can anyone help?
thanks
donna-LexusWebs wrote:
I added the VBA to an existing worksheet and although it did not expand myrows
18-Mar-10
I added the VBA to an existing worksheet and although it did not expand m
rows as soon as I added the code, as soon as I typed into the cell again th
row expanded and stayed expanded. I hope that helps
Thanks for the code - and the specific instructions where to add it (rt-cl
on the tab). I never knew that and always wondered how code was being added!
Thanks again
:
Previous Posts In This Thread:
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
I'm betting you have some "merged cells" which won't Autofit without VBA code.
I am betting you have some "merged cells" which will not Autofit without VBA code
If this is the case and you are interested in the code, post back
Gord Dibben MS Excel MV
wrote:
Nevermind!
Nevermind! Just realized my cells are merged - therefore, none of th
solutions I was trying will work
-
Caro
:
It is the case!
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
--
Caro
:
I avoid meged cells like the plague simply due to the many problems caused
I avoid meged cells like the plague simply due to the many problems caused b
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 Su
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
Gor
You (and Greg Wilson)...... BRILLIANT! Worked beautifully!
You (and Greg Wilson)...... BRILLIANT! Worked beautifully
Thank you for help - and perfect instruction
-
Caro
:
Does anyone know how to modify this code so that it will work in a protected
Does anyone know how to modify this code so that it will work in a protecte
sheet
:
Private Sub Worksheet_Change(ByVal Target As Range)Dim NewRwHt As SingleDim
Private Sub Worksheet_Change(ByVal Target As Range
Dim NewRwHt As Singl
Dim cWdth As Single, MrgeWdth As Singl
Dim c As Range, cc As Rang
Dim ma As Rang
On Error GoTo endi
Application.EnableEvents = Fals
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
Thank you, Gord!
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.
:
Re: Autosize cells as data is entered
Good to hear
Thanks for the feedback
wrote:
will this work for data that has already been entered into my sheet or will
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?
:
Only works when entering new data or editing existing data.
Only works when entering new data or editing existing data.
Gord
I added the VBA to an existing worksheet and although it did not expand myrows
I added the VBA to an existing worksheet and although it did not 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!
:
Submitted via EggHeadCafe - Software Developer Portal of Choice
WPF Report Engine, Part 1
http://www.eggheadcafe.com/tutorial...74-4eba5c821311/wpf-report-engine-part-1.aspx