#1
|
|||
|
|||
Help with VBA Code Modification
Hi All
I am looking for some help with modifying the vba code below. The code was kindly donated by another forum member adn I cannot remember who it was. However what I need is for the code not to run unless the text in an Excel cell exceeds the width of the cell. When the text exceeds the width of the cell it works fine. Any help would be 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 Tony (OTPM) |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
vbc code | rajpeter | Excel Programming | 2 | 09-13-2011 02:29 PM |
VBA code to change | carlleese24 | Excel Programming | 2 | 08-13-2011 09:48 AM |
The modification is not allowed because selection is locked | aligahk06 | Word | 0 | 09-06-2010 06:28 AM |
FileSaveAs with Code | bsmith | Office | 0 | 01-05-2006 08:43 AM |