Ngày mai trời lại sáng
Thành viên thường trực




- Tham gia
- 4/7/21
- Bài viết
- 339
- Được thích
- 139
Xin lỗi,mình quên không kèm theo file,mình gửi file phiền bạn xem giúp mình.Vậy giờ mình viết code lên ảnh trên hả bạn?
Option Explicit
Sub vidu()
'set formulas: '
'I6 = E6 + 1 '
'M6 = E6 + 2 '
'...to M24 '
'set print area B4:N29'
Const sCellNumPrint = "D2"
Const sCellRef = "E6"
Const numStep = 12
Dim ws As Worksheet, numPrint As Long, i As Long
Set ws = Sheet1
numPrint = VBA.Val(ws.Range(sCellNumPrint).Value2)
If numPrint = 0 Then Exit Sub
For i = 1 To numPrint
ws.Range(sCellRef).Value = 1 + numStep*(i-1)
'ws.PrintPreview 'preview
ws.PrintOut 'print
Next i
End Sub
Cảm ơn bạn ,đầu xuân chúc bạn sức khỏe và thành công.PHP:Option Explicit Sub vidu() 'set formulas: ' 'I6 = E6 + 1 ' 'M6 = E6 + 2 ' '...to M24 ' 'set print area B4:N29' Const sCellNumPrint = "D2" Const sCellRef = "E6" Const numStep = 12 Dim ws As Worksheet, numPrint As Long, i As Long Set ws = Sheet1 numPrint = VBA.Val(ws.Range(sCellNumPrint).Value2) If numPrint = 0 Then Exit Sub For i = 1 To numPrint ws.Range(sCellRef).Value = i + numStep 'ws.PrintPreview 'preview ws.PrintOut 'print Next i End Sub
Khi in tiếp lần nữa mà không nhập lại E6 thì sẽ lại bị trùng, có thể xử lý để sau mỗi lần in E6 tự lấy giá trị tiếp theo được không bạn?PHP:Option Explicit Sub vidu() 'set formulas: ' 'I6 = E6 + 1 ' 'M6 = E6 + 2 ' '...to M24 ' 'set print area B4:N29' Const sCellNumPrint = "D2" Const sCellRef = "E6" Const numStep = 12 Dim ws As Worksheet, numPrint As Long, i As Long Set ws = Sheet1 numPrint = VBA.Val(ws.Range(sCellNumPrint).Value2) If numPrint = 0 Then Exit Sub For i = 1 To numPrint ws.Range(sCellRef).Value = 1 + numStep*(i-1) 'ws.PrintPreview 'preview ws.PrintOut 'print Next i End Sub
2 ô ghi số là: ô A1 = 1000 và ô A2=2000Được quá đi chứ.
Bạn cần 2 ô ghi số từ đâu tới đâu.
Có 1 ô E6 thì chỉ được thế thôi.
Bao giờ thật thì làm bạn ơi.
Cảm ơn bạn mình đã sửa lại, làm phiền bạn.Bao giờ thật thì làm bạn ơi.
Mục đích là để làm gì mà phải kiểm soát số như thế vậy bạnVậy có thể mỗi lần mở file lên in là số có thể tiếp tục với lần in sau cùng trước đó mà không trùng lặp với các lần in trước cứ vậy cho đến 2000 thì thông báo hết số như vậy được không bạn, nếu được bạn code giúp mình với.
Cảm ơn bạn
Mình in phiếu ăn để phân phát cho mỗi người bạn à.Mục đích là để làm gì mà phải kiểm soát số như thế vậy bạn
Option Explicit
Sub vidu()
'set formulas: '
'I6 = E6 + 1 '
'M6 = E6 + 2 '
'...to M24 '
'set print area B4:N29'
Const sCellNumPrint = "D2"
Const sCellRef = "E6"
Const numStep = 12
Const sCellNoStart = "A1"
Const sCellNoEnd = "A2"
Const sCellNoLast = "A3"
Dim ws As Worksheet, numPrint As Long, i As Long
Dim noStart As Long, noEnd As Long, noLast As Long
Set ws = Sheet1
numPrint = VBA.Val(ws.Range(sCellNumPrint).Value2)
noStart = VBA.Val(ws.Range(sCellNoStart).Value2)
noEnd = VBA.Val(ws.Range(sCellNoEnd).Value2)
noLast = VBA.Val(ws.Range(sCellNoLast).Value2)
If numPrint = 0 Then Exit Sub
If noLast < noStart Then noLast = noStart - 1
For i = 1 To numPrint
noLast = noLast + 1
ws.Range(sCellRef).Value = noLast
'ws.PrintPreview 'preview
ws.PrintOut 'print
noLast = noLast + numStep
ws.Range(sCellNoLast).Value = noLast
If noLast > noEnd Then
MsgBox "Het so!", vbInformation
Exit Sub
End If
Next i
End Sub
Cảm ơn bạn nhiều nhiềuPHP:Option Explicit Sub vidu() 'set formulas: ' 'I6 = E6 + 1 ' 'M6 = E6 + 2 ' '...to M24 ' 'set print area B4:N29' Const sCellNumPrint = "D2" Const sCellRef = "E6" Const numStep = 12 Const sCellNoStart = "A1" Const sCellNoEnd = "A2" Const sCellNoLast = "A3" Dim ws As Worksheet, numPrint As Long, i As Long Dim noStart As Long, noEnd As Long, noLast As Long Set ws = Sheet1 numPrint = VBA.Val(ws.Range(sCellNumPrint).Value2) noStart = VBA.Val(ws.Range(sCellNoStart).Value2) noEnd = VBA.Val(ws.Range(sCellNoEnd).Value2) noLast = VBA.Val(ws.Range(sCellNoLast).Value2) If numPrint = 0 Then Exit Sub If noLast < noStart Then noLast = noStart - 1 For i = 1 To numPrint noLast = noLast + 1 ws.Range(sCellRef).Value = noLast 'ws.PrintPreview 'preview ws.PrintOut 'print noLast = noLast + numStep ws.Range(sCellNoLast).Value = noLast If noLast > noEnd Then MsgBox "Het so!", vbInformation Exit Sub End If Next i End Sub