LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Auto Size Wrapped/Merged Cells

Hello,
The following code works - with a couple flaws for which I'd like assistance
please.

The goal is to have the ranges CommentRange1 (C22:H22) and CommentRange2 (G43:
H43) auto adjust in height when the user inputs data in these ranges. This
works. However, at times, when the file is saved and later recalled, the said
ranges are hidden away.

Another flaw is that when selecting a range that includes the areas, say B22:
H22, it either hides the rows and/or errors in "The selection contains
multiple data values. Merging into one cell will keep the upper-mist left
data only." Btw, why does the option in the error says "OK" and "Cancel" when
both result in the same!? and Cancel does not cancel?

Help changing the existing code to prevent these errors and/or new code to
achieve the same would be greatly appreciated.

Stefan


Code:

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
' Auto adjust cell size for comment fields
Dim RowHt As Single, MergeWidth As Single
Dim C As Range, AutoFitRng As Range
Dim CWidth As Single, NewRowHt As Single
Static OldRngAdd As String
Dim OldRng As Range
On Error Resume Next
If bDisableEvents Then Exit Sub
If OldRngAdd = "" Then
Set OldRng = Union(Range("CommentRange1").MergeArea, Range
("CommentRange2").MergeArea)
OldRngAdd = OldRng.Address
Else
Set OldRng = Range(OldRngAdd)
End If
Set AutoFitRng = Union(Range("CommentRange1"), Range("CommentRange2"))
If Not Intersect(OldRng, AutoFitRng) Is Nothing Then
Application.ScreenUpdating = False
With OldRng
RowHt = .RowHeight
CWidth = .Cells(1).ColumnWidth
For Each C In OldRng
MergeWidth = C.ColumnWidth + MergeWidth
Next
.MergeCells = False
.Cells(1).ColumnWidth = MergeWidth
.EntireRow.AutoFit
NewRowHt = .RowHeight
.Cells(1).ColumnWidth = CWidth
.MergeCells = True
.RowHeight = NewRowHt
.Locked = False
End With
Application.ScreenUpdating = True
End If
OldRngAdd = Target.Address
End Sub

<fyi - this is a repost


--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200509/1
 
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 Row Height with Wrapped Text in Merged Cells Problem Rick Cl. Excel Discussion (Misc queries) 3 June 3rd 10 11:21 PM
Auto fit wrapped and merged cells in entire worksheet [email protected] Excel Discussion (Misc queries) 8 January 15th 09 06:50 PM
How do I auto adjust row height on merged columns w/wrapped text? ExcelBee Excel Discussion (Misc queries) 2 November 17th 06 04:48 AM
Excel - merged cells w/wrapped text auto row height doesn't work. Fred Excel Discussion (Misc queries) 0 October 21st 05 02:11 PM
Auto fit wrapped and merged cells elmo2 Excel Discussion (Misc queries) 1 January 17th 05 06:45 AM


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

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

About Us

"It's about Microsoft Excel"