NH_DK
Let's patience
- Tham gia
- 29/7/10
- Bài viết
- 865
- Được thích
- 1,203
- Nghề nghiệp
- Kế toán
Em đã viết:
Nhờ mọi người tối ưu code này cho em nhé!
PHP:
Option Explicit
Private Sub ComboBox1_Change()
Dim fRng As Range
Dim er As Long
Application.ScreenUpdating = False
On Error Resume Next
Set fRng = S1.Range("J:J").Find(Range("D8").Value, , xlValues, xlWhole)
If Not fRng Is Nothing Then
S14.Range("A14:K65000").Clear
With S1.Range(S1.[a2], S1.[a65000].End(3)).Offset(1).Resize(, 20)
.AutoFilter 2, ">=" & CLng(Range("E5").Value), 1, "<=" & CLng(Range("E6").Value)
.AutoFilter 1, "PX*"
.AutoFilter 10, Range("D8").Value
Union(.Offset(1, 1).Resize(, 3), .Offset(1, 8).Resize(, 1)).SpecialCells(12).Copy S14.[a14]
Union(.Offset(1, 12).Resize(, 1), .Offset(1, 16).Resize(, 2)).SpecialCells(12).Copy S14.[f14]
.Offset(1, 19).Resize(, 1).SpecialCells(12).Copy S14.[k14]
.AutoFilter
End With
Dim iR As Long, dongcuoi As Long
iR = Range("A30000").End(3).Row
With S14
For dongcuoi = iR To 14 Step -1
If .Cells(dongcuoi, 1) & .Cells(dongcuoi, 2) & .Cells(dongcuoi, 3) = .Cells(dongcuoi - 1, 1) & .Cells(dongcuoi - 1, 2) & _
.Cells(dongcuoi - 1, 3) Then .Cells(dongcuoi, 1).Resize(, 3) = Empty
Next
End With
S6.[A54:K61].Copy S14.[A65536].End(3).Offset(1)
With Range("A13").Offset(1).Resize(iR - 13, 11)
.BorderAround LineStyle:=1
.Borders(11).LineStyle = 1: .Borders(11).ColorIndex = 1
.Borders(12).LineStyle = 1: .Borders(12).ColorIndex = 1: .Borders(xlInsideHorizontal).Weight = xlThin
End With
With S14
.Cells(iR + 2, 8).Formula = "=SUM(R14C:R[-2]C)"
.Cells(iR + 2, 11).Formula = "=SUM(R14C:R[-2]C)"
.Cells(iR + 3, 8).Value = .Cells(iR + 2, 8).Value
.Cells(iR + 4, 8).Value = .Cells(iR + 2, 11).Value
.Cells(iR + 5, 8).Value = "=R[-2]C-R[-1]C"
.Cells(iR + 2, 8).Value = .Cells(iR + 2, 8).Value
.Cells(iR + 2, 11).Value = .Cells(iR + 2, 11).Value
.Cells(iR + 5, 8).Value = .Cells(iR + 5, 8).Value
End With
End If
End Sub