Hello all,
I got the code below, are there any way to disable screen update during the function ? The code make my sheet flicker The code adjust the row height of merged cells. (The area Name1 are meraged cells)
Gustaf
Private Sub CommandButton1_Click()
WrapText Range("Name1").Offset(0), 15.75, False
End Sub
Private Function WrapText(ByVal Target As Range, ByVal Max As Variant, lockCell As Boolean) As Variant
Dim NewRwHt As Single
Dim cWdth As Single, MrgeWdth As Single
Dim c As Range, cc As Range
Dim ma As Range
Application.ScreenUpdating = False
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 * 1.18
Next
On Error Resume Next
ma.MergeCells = False
c.ColumnWidth = MrgeWdth
c.EntireRow.AutoFit
NewRwHt = c.RowHeight
c.ColumnWidth = cWdth
ma.MergeCells = True
ma.RowHeight = WorksheetFunction.Max(NewRwHt, Max)
If (lockCell = True) Then
ma.Locked = True
Else
ma.Locked = False
End If
cWdth = 0: MrgeWdth = 0
On Error GoTo 0
End If
End With
WrapText = NewRwHt
Application.ScreenUpdating = True
End Function
I got the code below, are there any way to disable screen update during the function ? The code make my sheet flicker The code adjust the row height of merged cells. (The area Name1 are meraged cells)
Gustaf
Private Sub CommandButton1_Click()
WrapText Range("Name1").Offset(0), 15.75, False
End Sub
Private Function WrapText(ByVal Target As Range, ByVal Max As Variant, lockCell As Boolean) As Variant
Dim NewRwHt As Single
Dim cWdth As Single, MrgeWdth As Single
Dim c As Range, cc As Range
Dim ma As Range
Application.ScreenUpdating = False
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 * 1.18
Next
On Error Resume Next
ma.MergeCells = False
c.ColumnWidth = MrgeWdth
c.EntireRow.AutoFit
NewRwHt = c.RowHeight
c.ColumnWidth = cWdth
ma.MergeCells = True
ma.RowHeight = WorksheetFunction.Max(NewRwHt, Max)
If (lockCell = True) Then
ma.Locked = True
Else
ma.Locked = False
End If
cWdth = 0: MrgeWdth = 0
On Error GoTo 0
End If
End With
WrapText = NewRwHt
Application.ScreenUpdating = True
End Function