Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Tim Tim is offline
external usenet poster
 
Posts: 408
Default insert row when cell full, auto wrap

Hi there,
I used this code in ver 2003 to insert a row and wrap text in a cell..BUT,
it does not work in ver 2007. Any ideas? Much appreciated.

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default insert row when cell full, auto wrap

That code does not insert a row nor does it set a cell to wrap text.

All it does is allow autofitting rows with merged cells.

Cells must be preset to "Wrap Text"

Rows must to preset to "Autofit"

Then and only then will the merged cells autofit.


Gord Dibben MS Excel MVP

On Tue, 5 Jan 2010 15:16:02 -0800, Tim
wrote:

Hi there,
I used this code in ver 2003 to insert a row and wrap text in a cell..BUT,
it does not work in ver 2007. Any ideas? Much appreciated.

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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Auto wrap to another cell Jeremy Excel Discussion (Misc queries) 2 January 6th 10 05:39 PM
auto row height a cell with wrap text enabled and a lot of charact RichAll-68 New Users to Excel 0 January 20th 09 04:15 PM
Auto Text Wrap in a Cell Scott Douglas Excel Discussion (Misc queries) 1 July 5th 06 07:22 PM
auto tab when cell is full univarhb Excel Discussion (Misc queries) 3 April 27th 06 10:21 PM
Insert cell/format/text/fontsize and auto insert into header? Unfurltheflag Excel Programming 2 November 3rd 04 05:39 PM


All times are GMT +1. The time now is 12:12 AM.

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

About Us

"It's about Microsoft Excel"