Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 58
Default "Resizing cells" code doesn't work with merged cells

I got a code I found on this site to resize my cells as I type:

Private Sub Worksheet_Change(ByVal Target As Range)
Set t = Target
Application.EnableEvents = False
Rows(t.Row).EntireRow.AutoFit
Application.EnableEvents = True
End Sub

But it doesn't work on merged cells. Is there an additional code that can
be added to the above to include merged cells?

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default "Resizing cells" code doesn't work with merged cells

You need a little more code when working with those sheet-wrecking merged cells.

Here is 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


Gord Dibben MS Excel MVP

On Thu, 26 Jun 2008 08:23:01 -0700, Gina wrote:

I got a code I found on this site to resize my cells as I type:

Private Sub Worksheet_Change(ByVal Target As Range)
Set t = Target
Application.EnableEvents = False
Rows(t.Row).EntireRow.AutoFit
Application.EnableEvents = True
End Sub

But it doesn't work on merged cells. Is there an additional code that can
be added to the above to include merged cells?


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 58
Default "Resizing cells" code doesn't work with merged cells

That did it!!! Thank you so much!

"Gord Dibben" wrote:

You need a little more code when working with those sheet-wrecking merged cells.

Here is 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


Gord Dibben MS Excel MVP

On Thu, 26 Jun 2008 08:23:01 -0700, Gina wrote:

I got a code I found on this site to resize my cells as I type:

Private Sub Worksheet_Change(ByVal Target As Range)
Set t = Target
Application.EnableEvents = False
Rows(t.Row).EntireRow.AutoFit
Application.EnableEvents = True
End Sub

But it doesn't work on merged cells. Is there an additional code that can
be added to the above to include merged cells?



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
Repeat code to "n" cells Kelson New Users to Excel 1 October 10th 07 11:19 PM
Work in 2 Cells "C3" and "R3" Steved Excel Worksheet Functions 10 May 23rd 07 11:48 PM
Odd error - "This operation requires merged cells..." Maury Markowitz New Users to Excel 3 September 14th 06 01:54 AM
sort spreadsheet, "merged cells" comes up. Find cells? Unmerge ? lowell Excel Discussion (Misc queries) 1 August 20th 06 09:10 AM
Can't copy & paste - "merged cells must be identically sized" Rayo K Excel Discussion (Misc queries) 2 March 14th 06 12:19 AM


All times are GMT +1. The time now is 11:37 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"