Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-16-2011, 07:10 AM
OTPM OTPM is offline Help with VBA Code Modification Windows 7 32bit Help with VBA Code Modification Office 2010 32bit
Expert
Help with VBA Code Modification
 
Join Date: Apr 2011
Location: West Midlands
Posts: 981
OTPM is on a distinguished road
Default 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)
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with VBA Code Modification vbc code rajpeter Excel Programming 2 09-13-2011 02:29 PM
Help with VBA Code Modification 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

Other Forums: Access Forums

All times are GMT -7. The time now is 02:11 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft