
ลองดูตัวอย่างการปรับ Code ตามไฟล์แนบครับ
Code: Select all
Sub SaveAndPrint()
Dim J As Integer 'No. of Row in Bill
Dim K As Integer 'End of Row
Dim M As Integer 'Commulative Row in the day
Dim RefNo As Integer
Application.ScreenUpdating = False
Cells(1, 2).Value = Cells(1, 2) + 1
RefNo = Cells(1, 2).Value
J = 17 - WorksheetFunction.CountIf(Range("c3:c19"), "")
K = J + 2
M = Cells(1, 9).Value 'Set M = 0 for Ref.No=1
'PRINT
Sheet3.Activate
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
IgnorePrintAreas:=False
'SAVE
Range(Cells(24, 3), Cells(23 + J, 3)).Copy
Range(Cells(M + 34, 3), Cells(M + J + 34, 3)).PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Range(Cells(24, 5), Cells(23 + J, 5)).Copy
Range(Cells(M + 34, 5), Cells(M + J + 34, 5)).PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False
M = M + J
Cells(1, 9).Value = M
Cells(34 + M - J, 1).Value = RefNo
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
You do not have the required permissions to view the files attached to this post.