mrvuonghuyen
Thành viên mới

- Tham gia
- 4/4/12
- Bài viết
- 2
- Được thích
- 0
Nhờ anh chị giải thích hộ em câu lệnh này với ạ
Sub ()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Dim i, k, T1, T2, dem As Long
r = ActiveSheet.UsedRange.Rows.Count
On Error Resume Next
T1 = Application.WorksheetFunction.CountA(Range("A4:A65000")) / 6
T2 = Application.WorksheetFunction.CountA(Range("N4:N65000"))
dem = T2 / T1
Cells(9, 16) = Cells(6, 1)
For i = 9 To r Step dem + 6
For k = 1 To dem - 1
If Cells(i + k, 3) > 0 Then
Cells(i + k, 17) = Cells(i + k, 2)
Cells(i + k, 18) = Cells(i + k, 3) / 100
Cells(i + k, 19) = Cells(i + k, 4)
End If
Range(Cells(i, 17), Cells(i + dem, 19)).Select
Selection.Sort Key1:=Range("Q6"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Next k
Next i
For i = 6 To r Step dem + 6
Cells(i + dem + 9, 16) = Cells(i + dem + 6, 1)
If Cells(i, 17) <> 0 Then
Cells(i + 1, 16) = Cells(i, 16)
End If
Next i
For i = 9 To r
If Cells(i, 17) <> 0 And Cells(i + 1, 17) <> 0 Then
Cells(i + 1, 16) = Cells(i, 16)
End If
Next i
Columns("P:S").Select
Selection.Sort Key1:=Range("P1"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Sub ()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Dim i, k, T1, T2, dem As Long
r = ActiveSheet.UsedRange.Rows.Count
On Error Resume Next
T1 = Application.WorksheetFunction.CountA(Range("A4:A65000")) / 6
T2 = Application.WorksheetFunction.CountA(Range("N4:N65000"))
dem = T2 / T1
Cells(9, 16) = Cells(6, 1)
For i = 9 To r Step dem + 6
For k = 1 To dem - 1
If Cells(i + k, 3) > 0 Then
Cells(i + k, 17) = Cells(i + k, 2)
Cells(i + k, 18) = Cells(i + k, 3) / 100
Cells(i + k, 19) = Cells(i + k, 4)
End If
Range(Cells(i, 17), Cells(i + dem, 19)).Select
Selection.Sort Key1:=Range("Q6"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Next k
Next i
For i = 6 To r Step dem + 6
Cells(i + dem + 9, 16) = Cells(i + dem + 6, 1)
If Cells(i, 17) <> 0 Then
Cells(i + 1, 16) = Cells(i, 16)
End If
Next i
For i = 9 To r
If Cells(i, 17) <> 0 And Cells(i + 1, 17) <> 0 Then
Cells(i + 1, 16) = Cells(i, 16)
End If
Next i
Columns("P:S").Select
Selection.Sort Key1:=Range("P1"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub