vc_đi chơi
Thành viên hoạt động



- Tham gia
- 21/9/19
- Bài viết
- 176
- Được thích
- 35
Em có tham khảo đoạn code để dãn dòng Trên GPE và áp dụng:
Trong sheet"Bang" được lấy dữ liệu từ sheet"Nguon".
+ Sub Dandong() em copy vào sheet"Bang" nhu sau":
+ Sub MergeCellFit(ByVal MergeCells As Range) em copy vào module1:
Khi Cuộn dữ liệu em không thấy tác dụng giãn dòng trên các vùng ô được gộp của sheet "Bang"
Cách copy code vào vị trí vậy đã đúng chưa ạ?
Nhờ các anh, chị giúp em xem còn lỗi gì mà không giãn dòng được ạ?
Mong anh, chị giúp đỡ. Em cảm ơn!

Trong sheet"Bang" được lấy dữ liệu từ sheet"Nguon".
+ Sub Dandong() em copy vào sheet"Bang" nhu sau":
Mã:
Sub Dandong()
Dim cll As Range
On Error Resume Next
For Each cll In Range("F11", Range("F" & Rows.Count).End(xlUp))
If cll <> Empty Then MergeCellFit cll.Offset(, -3)
Next
End Sub
Mã:
Sub MergeCellFit(ByVal MergeCells As Range)
Dim Diff As Single
Dim FirstCell As Range, MergeCellArea As Range
Dim col As Long, ColCount As Long, RowCount As Long
Dim FirstCellWidth As Double, FirstCellHeight As Double, MergeCellWidth As Double
If MergeCells.Count = 1 Then
Set MergeCellArea = MergeCells.MergeArea
Else
Set MergeCellArea = MergeCells
End If
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
With MergeCellArea
ColCount = .Columns.Count
RowCount = .Rows.Count
.WrapText = True
If RowCount = 1 And ColCount = 1 Then
.EntireRow.AutoFit
GoTo ExitSub
End If
Set FirstCell = .Cells(1, 1)
FirstCellWidth = FirstCell.ColumnWidth
Diff = 0.75
For col = 1 To ColCount
MergeCellWidth = MergeCellWidth + .Cells(1, col).ColumnWidth + Diff
Next
.MergeCells = False
FirstCell.ColumnWidth = MergeCellWidth - Diff
.EntireRow.AutoFit
FirstCellHeight = FirstCell.RowHeight
.MergeCells = True
FirstCell.ColumnWidth = FirstCellWidth
FirstCellHeight = FirstCellHeight / RowCount
.RowHeight = FirstCellHeight
End With
ExitSub:
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
Cách copy code vào vị trí vậy đã đúng chưa ạ?
Nhờ các anh, chị giúp em xem còn lỗi gì mà không giãn dòng được ạ?
Mong anh, chị giúp đỡ. Em cảm ơn!
