Trouble with "target.value" when cancelling...
The below code was adapted from Jim Rech's original code on the subject. To
my knowledge he originated this approach. Assuming that columns are merged
and that cell A3 is the active cell in the merged range:
Dim OldRng As Range 'Delare this at top of module
Private Sub Worksheet_SelectionChange(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
Set c = Range("A3")
If OldRng Is Nothing Then Set OldRng = c
If Not Intersect(OldRng, c) Is Nothing Then
Application.ScreenUpdating = False
cWdth = c.ColumnWidth
Set ma = c.MergeArea
For Each cc In ma.Cells
MrgeWdth = MrgeWdth + cc.ColumnWidth
Next
ma.MergeCells = False
c.ColumnWidth = MrgeWdth
c.EntireRow.AutoFit
NewRwHt = c.RowHeight
c.ColumnWidth = cWdth
ma.MergeCells = True
ma.RowHeight = NewRwHt
Application.ScreenUpdating = True
End If
Set OldRng = Target
End Sub
Regards,
Greg
|