Created
February 21, 2018 04:56
-
-
Save DuongAQ/2244a97db5a5afa6c3422a74ab07f054 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Private Sub Worksheet_Change(ByVal Target As Range) 'Tự động giãn dòng vùng đã trộn ô | |
Dim MergeWidth As Single | |
Dim cM As Range | |
Dim AutoFitRng As Range | |
Dim CWidth As Double | |
Dim NewRowHt As Double | |
Dim str01 As String | |
str01 = "OrderNote" | |
'OrderNote = Tên vùng trộn ô | |
If Not Intersect(Target, Range(str01)) Is Nothing Then | |
Application.ScreenUpdating = False | |
On Error Resume Next | |
Set AutoFitRng = Range(Range(str01).MergeArea.Address) | |
With AutoFitRng | |
.MergeCells = False | |
CWidth = .Cells(1).ColumnWidth | |
MergeWidth = 0 | |
For Each cM In AutoFitRng | |
cM.WrapText = True | |
MergeWidth = cM.ColumnWidth + MergeWidth | |
Next | |
'Điều chỉnh 1 chút về độ rộng tạm thời: | |
MergeWidth = MergeWidth + AutoFitRng.Cells.Count * 0.66 | |
.Cells(1).ColumnWidth = MergeWidth | |
.EntireRow.AutoFit | |
NewRowHt = .RowHeight | |
.Cells(1).ColumnWidth = CWidth | |
.MergeCells = True | |
.RowHeight = NewRowHt | |
End With | |
Application.ScreenUpdating = True | |
End If | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment