duyhuynh9922
Thành viên mới
- Tham gia
- 25/10/21
- Bài viết
- 16
- Được thích
- 8
Xin chào các anh, chi. Hiện tại em có 1 thắc mắc là khi thực hiện đoạn code này với số lượng khoảng 3000 công nhân thì liệu excel có kịp load đúng dữ liệu cần in không ạ. Với mỗi ô tô màu vàng thì đều sử dụng hàm vLookup. Mong đc giải đáp!!!
Mã:
Public Sub PRINTING()
Dim MAX, U, Y, A As Integer
Dim SARR()
Dim WSPR, WSDT As Worksheet
Dim DA, DB, DC, DD, DE
Application.ActivePrinter = "RICOH Aficio MP 4001 PCL 6 ON NE00:"
Application.Calculation = xlCalculationAutomatic
Set WSDT = ThisWorkbook.Sheets("DD")
Set WSPR = ThisWorkbook.Sheets("FF")
MAX = WSDT.Range("A" & Rows.Count).End(xlUp).Row
SARR = WSDT.Range("A1:C" & MAX).Value
DC = MAX Mod 5
If DC = 0 Then
For A = 1 To UBound(SARR)
Y = Y + 1
If Y = 1 Then
WSPR.Range("A5").Value = SARR(A, 1)
ElseIf Y = 2 Then
WSPR.Range("A15").Value = SARR(A, 1)
ElseIf Y = 3 Then
WSPR.Range("A25").Value = SARR(A, 1)
ElseIf Y = 4 Then
WSPR.Range("A35").Value = SARR(A, 1)
ElseIf Y = 5 Then
WSPR.Range("A45").Value = SARR(A, 1)
Y = 0
ActiveSheet.PageSetup.PrintArea = "$A$1:$R$49"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
IgnorePrintAreas:=False
End If
Next A
ElseIf DC = 1 Then
For A = 1 To UBound(SARR)
DA = DA + 1
If DA <= MAX - 1 Then
Y = Y + 1
If Y = 1 Then
WSPR.Range("A5").Value = SARR(A, 1)
ElseIf Y = 2 Then
WSPR.Range("A15").Value = SARR(A, 1)
ElseIf Y = 3 Then
WSPR.Range("A25").Value = SARR(A, 1)
ElseIf Y = 4 Then
WSPR.Range("A35").Value = SARR(A, 1)
ElseIf Y = 5 Then
WSPR.Range("A45").Value = SARR(A, 1)
Y = 0
ActiveSheet.PageSetup.PrintArea = "$A$1:$R$49"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
IgnorePrintAreas:=False
End If
Else
WSPR.Range("A5").Value = SARR(A, 1)
ActiveSheet.PageSetup.PrintArea = "$A$1:$R$10"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
IgnorePrintAreas:=False
End If
Next A
ElseIf DC = 2 Then
For A = 1 To UBound(SARR)
DA = DA + 1
If DA <= MAX - 2 Then
Y = Y + 1
If Y = 1 Then
WSPR.Range("A5").Value = SARR(A, 1)
ElseIf Y = 2 Then
WSPR.Range("A15").Value = SARR(A, 1)
ElseIf Y = 3 Then
WSPR.Range("A25").Value = SARR(A, 1)
ElseIf Y = 4 Then
WSPR.Range("A35").Value = SARR(A, 1)
ElseIf Y = 5 Then
WSPR.Range("A45").Value = SARR(A, 1)
Y = 0
ActiveSheet.PageSetup.PrintArea = "$A$1:$R$49"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
IgnorePrintAreas:=False
End If
Else
ActiveSheet.PageSetup.PrintArea = "$A$1:$R$20"
DB = DB + 1
If DB = 1 Then
WSPR.Range("A5").Value = SARR(A, 1)
Else
WSPR.Range("A15").Value = SARR(A, 1)
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
IgnorePrintAreas:=False
End If
End If
Next A
ElseIf DC = 3 Then
For A = 1 To UBound(SARR)
DA = DA + 1
If DA <= MAX - 3 Then
Y = Y + 1
If Y = 1 Then
WSPR.Range("A5").Value = SARR(A, 1)
ElseIf Y = 2 Then
WSPR.Range("A15").Value = SARR(A, 1)
ElseIf Y = 3 Then
WSPR.Range("A25").Value = SARR(A, 1)
ElseIf Y = 4 Then
WSPR.Range("A35").Value = SARR(A, 1)
ElseIf Y = 5 Then
WSPR.Range("A45").Value = SARR(A, 1)
Y = 0
ActiveSheet.PageSetup.PrintArea = "$A$1:$R$49"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
IgnorePrintAreas:=False
End If
Else
ActiveSheet.PageSetup.PrintArea = "$A$1:$R$30"
DB = DB + 1
If DB = 1 Then
WSPR.Range("A5").Value = SARR(A, 1)
ElseIf DB = 2 Then
WSPR.Range("A15").Value = SARR(A, 1)
Else
WSPR.Range("A25").Value = SARR(A, 1)
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
IgnorePrintAreas:=False
End If
End If
Next A
ElseIf DC = 4 Then
For A = 1 To UBound(SARR)
DA = DA + 1
If DA <= MAX - 4 Then
Y = Y + 1
If Y = 1 Then
WSPR.Range("A5").Value = SARR(A, 1)
ElseIf Y = 2 Then
WSPR.Range("A15").Value = SARR(A, 1)
ElseIf Y = 3 Then
WSPR.Range("A25").Value = SARR(A, 1)
ElseIf Y = 4 Then
WSPR.Range("A35").Value = SARR(A, 1)
ElseIf Y = 5 Then
WSPR.Range("A45").Value = SARR(A, 1)
Y = 0
ActiveSheet.PageSetup.PrintArea = "$A$1:$R$49"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
IgnorePrintAreas:=False
End If
Else
ActiveSheet.PageSetup.PrintArea = "$A$1:$R$40"
DB = DB + 1
If DB = 1 Then
WSPR.Range("A5").Value = SARR(A, 1)
ElseIf DB = 2 Then
WSPR.Range("A15").Value = SARR(A, 1)
ElseIf DB = 3 Then
WSPR.Range("A25").Value = SARR(A, 1)
Else
WSPR.Range("A35").Value = SARR(A, 1)
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
IgnorePrintAreas:=False
End If
End If
Next A
Else
End If
End Sub
Lần chỉnh sửa cuối: