Nhờ anh chị giải thích hộ em câu lệnh này với ạ (1 người xem)

Liên hệ QC

Người dùng đang xem chủ đề này

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
 
Mã:
Sub haydoiday()
Application.DisplayAlerts = False ' tat thong bao cua excel
Application.ScreenUpdating = False ' giup cho man hinh khong bi giat giat
Dim i, k, T1, T2, dem As Long ' khai bao bien
r = ActiveSheet.UsedRange.Rows.Count ' cai r bang so dong trong vung co so lieu
On Error Resume Next 'co loi xay thi thay ke no, cu lam tiep di
T1 = Application.WorksheetFunction.CountA(Range("A4:A65 000")) / 6 ' ham counta nhu trong worksheet
T2 = Application.WorksheetFunction.CountA(Range("N4:N65 000"))
dem = T2 / T1
Cells(9, 16) = Cells(6, 1) ' gan gia tri cell I16=F1
For i = 9 To r Step dem + 6 ' vòng lap cho i chay tu 9 den r voi buoc nhay dem+6
    For k = 1 To dem - 1 'vong lap k chay tu 1 den dem-1
        If Cells(i + k, 3) > 0 Then 'neu cac cell trong cot C (tu C10 tro di) lon hon 0)
            Cells(i + k, 17) = Cells(i + k, 2) ' gan gia tri vao cac cell truoc dau phay la dong, sau dau phai la cot
            Cells(i + k, 18) = Cells(i + k, 3) / 100
            Cells(i + k, 19) = Cells(i + k, 4)
        End If ' ket thuc lech if
    Range(Cells(i, 17), Cells(i + dem, 19)).Select ' chon cell
    Selection.Sort Key1:=Range("Q6"), Order1:=xlAscending, Header:=xlGuess, _
    OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
    DataOption1:=xlSortNormal ' lenh sort cot Q
    Next k
Next i
........tuong tự nhu vậy
 
Upvote 0
Chỉnh sửa lần cuối bởi điều hành viên:
Upvote 0
Web KT

Bài viết mới nhất

Back
Top Bottom