Help! Nhờ tự động xóa hàm khi chạy File in

Liên hệ QC

thanhtung0112

Thành viên chính thức
Tham gia
24/1/17
Bài viết
51
Được thích
5
Hiện tại mình có 1 File in tự động, nhưng vì mỗi STT là số lượng công nhân khác nhau, mà khi mịnh in chạy File thì hàm nó không bỏ đi được, cho nên sẽ in bị dư giấy. Nhớ mấy huynh giúp em xóa hàm dư với, Em xin cảm ơn.
File hình nè mấy huynh.
1572597847455.png
 

File đính kèm

Hiện tại mình có 1 File in tự động, nhưng vì mỗi STT là số lượng công nhân khác nhau, mà khi mịnh in chạy File thì hàm nó không bỏ đi được, cho nên sẽ in bị dư giấy. Nhớ mấy huynh giúp em xóa hàm dư với, Em xin cảm ơn.
File hình nè mấy huynh.
View attachment 227562
Nếu xóa công thức đi thì cái sau làm sao mà nhận được giá trị để in chứ.Chỉ viết code khác là nhanh thôi.
 
Upvote 0
bởi, khả năng mình tới đó hoy, nên nhờ mấy huynh giúp đỡ nè, hiz
Bạn thử xem đúng không nhé.Bỏ hết công thức cả 2 sheets không cần dùng.
Mã:
Sub innhanh()
Application.ScreenUpdating = False
    Dim a As Long, b As Long, i As Long, dic As Object, arr, lr As Long, s As String, dk As String, kq, data, T, k As Long
    Set dic = CreateObject("scripting.dictionary")
    With Sheets("data")
         lr = .Range("D" & Rows.Count).End(xlUp).Row
         arr = .Range("D2:J" & lr).Value
         For i = 1 To UBound(arr)
             dk = UCase(arr(i, 6))
             If Not dic.exists(dk) Then
                dic.Add dk, "#" & i
             Else
                dic.Item(dk) = dic.Item(dk) & "#" & i
             End If
         Next i
    End With
    With Sheets("DS")
         a = .Range("s5").Value - 1
         b = .Range("s6").Value - 1
    End With
    If a > b Then MsgBox "nhap so sai": Exit Sub
    If b > dic.Count Then MsgBox "qua lon": Exit Sub
    data = dic.keys
    With Sheets("DS")
         For i = a To b
             a = 0
             s = dic.Item(data(i))
             T = Split(s, "#")
             ReDim kq(1 To UBound(T), 1 To 4)
             For k = 1 To UBound(T)
                 a = a + 1
                 kq(a, 1) = a
                 kq(a, 2) = arr(T(k), 2)
                 kq(a, 3) = arr(T(k), 3)
                 kq(a, 4) = arr(T(k), 4)
             Next k
             .Range("A15:D999").ClearContents
             .Rows("15:999").EntireRow.Hidden = False
             If a Then
                .Range("A15:D15").Resize(a).Value = kq
                .Rows(a + 16 & ":998").EntireRow.Hidden = True
             End If
             .PrintOut
             '.PrintPreview
         Next i
   End With
Application.ScreenUpdating = True
End Sub
 

File đính kèm

Upvote 0
Bạn thử xem đúng không nhé.Bỏ hết công thức cả 2 sheets không cần dùng.
Mã:
Sub innhanh()
Application.ScreenUpdating = False
    Dim a As Long, b As Long, i As Long, dic As Object, arr, lr As Long, s As String, dk As String, kq, data, T, k As Long
    Set dic = CreateObject("scripting.dictionary")
    With Sheets("data")
         lr = .Range("D" & Rows.Count).End(xlUp).Row
         arr = .Range("D2:J" & lr).Value
         For i = 1 To UBound(arr)
             dk = UCase(arr(i, 6))
             If Not dic.exists(dk) Then
                dic.Add dk, "#" & i
             Else
                dic.Item(dk) = dic.Item(dk) & "#" & i
             End If
         Next i
    End With
    With Sheets("DS")
         a = .Range("s5").Value - 1
         b = .Range("s6").Value - 1
    End With
    If a > b Then MsgBox "nhap so sai": Exit Sub
    If b > dic.Count Then MsgBox "qua lon": Exit Sub
    data = dic.keys
    With Sheets("DS")
         For i = a To b
             a = 0
             s = dic.Item(data(i))
             T = Split(s, "#")
             ReDim kq(1 To UBound(T), 1 To 4)
             For k = 1 To UBound(T)
                 a = a + 1
                 kq(a, 1) = a
                 kq(a, 2) = arr(T(k), 2)
                 kq(a, 3) = arr(T(k), 3)
                 kq(a, 4) = arr(T(k), 4)
             Next k
             .Range("A15:D999").ClearContents
             .Rows("15:999").EntireRow.Hidden = False
             If a Then
                .Range("A15:D15").Resize(a).Value = kq
                .Rows(a + 16 & ":998").EntireRow.Hidden = True
             End If
             .PrintOut
             '.PrintPreview
         Next i
   End With
Application.ScreenUpdating = True
End Sub
1572667218960.png
bộ phận s nó ra ngày tháng năm sinh r nè bạn ơi
 
Upvote 0
View attachment 227615
bộ phận s nó ra ngày tháng năm sinh r nè bạn ơi
Buồn ngủ chắc nhìn nhầm.Bạn thử code này.
Mã:
Sub innhanh()
Application.ScreenUpdating = False
    Dim a As Long, b As Long, i As Long, dic As Object, arr, lr As Long, s As String, dk As String, kq, data, T, k As Long
    Set dic = CreateObject("scripting.dictionary")
    With Sheets("data")
         lr = .Range("D" & Rows.Count).End(xlUp).Row
         arr = .Range("D2:J" & lr).Value
         For i = 1 To UBound(arr)
             dk = UCase(arr(i, 6))
             If Not dic.exists(dk) Then
                dic.Add dk, "#" & i
             Else
                dic.Item(dk) = dic.Item(dk) & "#" & i
             End If
         Next i
    End With
    With Sheets("DS")
         a = .Range("s5").Value - 1
         b = .Range("s6").Value - 1
    End With
    If a > b Then MsgBox "nhap so sai": Exit Sub
    If b > dic.Count Then MsgBox "qua lon": Exit Sub
    data = dic.keys
    With Sheets("DS")
         For i = a To b
             a = 0
             s = dic.Item(data(i))
             T = Split(s, "#")
             ReDim kq(1 To UBound(T), 1 To 4)
             For k = 1 To UBound(T)
                 a = a + 1
                 kq(a, 1) = a
                 kq(a, 2) = arr(T(k), 2)
                 kq(a, 3) = arr(T(k), 3)
                 kq(a, 4) = arr(T(k), 6)
             Next k
             .Range("A15:D999").ClearContents
             .Rows("15:999").EntireRow.Hidden = False
             If a Then
                .Range("A15:D15").Resize(a).Value = kq
                .Rows(a + 16 & ":998").EntireRow.Hidden = True
             End If
             .PrintOut
             '.PrintPreview
         Next i
   End With
Application.ScreenUpdating = True
End Sub
Bài đã được tự động gộp:

Buồn ngủ chắc nhìn nhầm.Bạn thử code này.
Mã:
Sub innhanh()
Application.ScreenUpdating = False
    Dim a As Long, b As Long, i As Long, dic As Object, arr, lr As Long, s As String, dk As String, kq, data, T, k As Long
    Set dic = CreateObject("scripting.dictionary")
    With Sheets("data")
         lr = .Range("D" & Rows.Count).End(xlUp).Row
         arr = .Range("D2:J" & lr).Value
         For i = 1 To UBound(arr)
             dk = UCase(arr(i, 6))
             If Not dic.exists(dk) Then
                dic.Add dk, "#" & i
             Else
                dic.Item(dk) = dic.Item(dk) & "#" & i
             End If
         Next i
    End With
    With Sheets("DS")
         a = .Range("s5").Value - 1
         b = .Range("s6").Value - 1
    End With
    If a > b Then MsgBox "nhap so sai": Exit Sub
    If b > dic.Count Then MsgBox "qua lon": Exit Sub
    data = dic.keys
    With Sheets("DS")
         For i = a To b
             a = 0
             s = dic.Item(data(i))
             T = Split(s, "#")
             ReDim kq(1 To UBound(T), 1 To 4)
             For k = 1 To UBound(T)
                 a = a + 1
                 kq(a, 1) = a
                 kq(a, 2) = arr(T(k), 2)
                 kq(a, 3) = arr(T(k), 3)
                 kq(a, 4) = arr(T(k), 6)
             Next k
             .Range("A15:D999").ClearContents
             .Rows("15:999").EntireRow.Hidden = False
             If a Then
                .Range("A15:D15").Resize(a).Value = kq
                .Rows(a + 16 & ":998").EntireRow.Hidden = True
             End If
             .PrintOut
             '.PrintPreview
         Next i
   End With
Application.ScreenUpdating = True
End Sub
Bạn sửa theo code này nhé.
Mã:
Sub innhanh()
Application.ScreenUpdating = False
    Dim a As Long, b As Long, i As Long, dic As Object, arr, lr As Long, s As String, dk As String, kq, data, T, k As Long, c As Long
    Set dic = CreateObject("scripting.dictionary")
    With Sheets("data")
         lr = .Range("D" & Rows.Count).End(xlUp).Row
         arr = .Range("D2:J" & lr).Value
         For i = 1 To UBound(arr)
             dk = UCase(arr(i, 6))
             If Not dic.exists(dk) Then
                dic.Add dk, "#" & i
             Else
                dic.Item(dk) = dic.Item(dk) & "#" & i
             End If
         Next i
    End With
    With Sheets("DS")
         a = .Range("s5").Value - 1
         b = .Range("s6").Value - 1
    End With
    If a > b Then MsgBox "nhap so sai": Exit Sub
    If b > dic.Count Then MsgBox "qua lon": Exit Sub
    data = dic.keys
    With Sheets("DS")
         For i = a To b
             c = 0
             s = dic.Item(data(i))
             T = Split(s, "#")
             ReDim kq(1 To UBound(T), 1 To 4)
             For k = 1 To UBound(T)
                 c = c + 1
                 kq(c, 1) = c
                 kq(c, 2) = arr(T(k), 2)
                 kq(c, 3) = arr(T(k), 3)
                 kq(c, 4) = arr(T(k), 6)
             Next k
             .Range("A15:D999").ClearContents
             .Rows("15:999").EntireRow.Hidden = False
             If c Then
                .Range("A15:D15").Resize(c).Value = kq
                .Rows(c + 16 & ":998").EntireRow.Hidden = True
             End If
             .PrintOut
             '.PrintPreview
         Next i
   End With
Application.ScreenUpdating = True
End Sub
 
Lần chỉnh sửa cuối:
Upvote 0
Buồn ngủ chắc nhìn nhầm.Bạn thử code này.
Mã:
Sub innhanh()
Application.ScreenUpdating = False
    Dim a As Long, b As Long, i As Long, dic As Object, arr, lr As Long, s As String, dk As String, kq, data, T, k As Long
    Set dic = CreateObject("scripting.dictionary")
    With Sheets("data")
         lr = .Range("D" & Rows.Count).End(xlUp).Row
         arr = .Range("D2:J" & lr).Value
         For i = 1 To UBound(arr)
             dk = UCase(arr(i, 6))
             If Not dic.exists(dk) Then
                dic.Add dk, "#" & i
             Else
                dic.Item(dk) = dic.Item(dk) & "#" & i
             End If
         Next i
    End With
    With Sheets("DS")
         a = .Range("s5").Value - 1
         b = .Range("s6").Value - 1
    End With
    If a > b Then MsgBox "nhap so sai": Exit Sub
    If b > dic.Count Then MsgBox "qua lon": Exit Sub
    data = dic.keys
    With Sheets("DS")
         For i = a To b
             a = 0
             s = dic.Item(data(i))
             T = Split(s, "#")
             ReDim kq(1 To UBound(T), 1 To 4)
             For k = 1 To UBound(T)
                 a = a + 1
                 kq(a, 1) = a
                 kq(a, 2) = arr(T(k), 2)
                 kq(a, 3) = arr(T(k), 3)
                 kq(a, 4) = arr(T(k), 6)
             Next k
             .Range("A15:D999").ClearContents
             .Rows("15:999").EntireRow.Hidden = False
             If a Then
                .Range("A15:D15").Resize(a).Value = kq
                .Rows(a + 16 & ":998").EntireRow.Hidden = True
             End If
             .PrintOut
             '.PrintPreview
         Next i
   End With
Application.ScreenUpdating = True
End Sub
Bài đã được tự động gộp:


Bạn sửa theo code này nhé.
Mã:
Sub innhanh()
Application.ScreenUpdating = False
    Dim a As Long, b As Long, i As Long, dic As Object, arr, lr As Long, s As String, dk As String, kq, data, T, k As Long, c As Long
    Set dic = CreateObject("scripting.dictionary")
    With Sheets("data")
         lr = .Range("D" & Rows.Count).End(xlUp).Row
         arr = .Range("D2:J" & lr).Value
         For i = 1 To UBound(arr)
             dk = UCase(arr(i, 6))
             If Not dic.exists(dk) Then
                dic.Add dk, "#" & i
             Else
                dic.Item(dk) = dic.Item(dk) & "#" & i
             End If
         Next i
    End With
    With Sheets("DS")
         a = .Range("s5").Value - 1
         b = .Range("s6").Value - 1
    End With
    If a > b Then MsgBox "nhap so sai": Exit Sub
    If b > dic.Count Then MsgBox "qua lon": Exit Sub
    data = dic.keys
    With Sheets("DS")
         For i = a To b
             c = 0
             s = dic.Item(data(i))
             T = Split(s, "#")
             ReDim kq(1 To UBound(T), 1 To 4)
             For k = 1 To UBound(T)
                 c = c + 1
                 kq(c, 1) = c
                 kq(c, 2) = arr(T(k), 2)
                 kq(c, 3) = arr(T(k), 3)
                 kq(c, 4) = arr(T(k), 6)
             Next k
             .Range("A15:D999").ClearContents
             .Rows("15:999").EntireRow.Hidden = False
             If c Then
                .Range("A15:D15").Resize(c).Value = kq
                .Rows(c + 16 & ":998").EntireRow.Hidden = True
             End If
             .PrintOut
             '.PrintPreview
         Next i
   End With
Application.ScreenUpdating = True
End Sub
Được rồi bạn ơi, cảm ơn bạn nhiều lắm, mà nó bị dư 2 hàng, có xóa được không bạn
1572669638108.png
 
Upvote 0
Được rồi bạn ơi, cảm ơn bạn nhiều lắm, mà nó bị dư 2 hàng, có xóa được không bạn
View attachment 227618
Bạn thử.
Mã:
Sub innhanh()
Application.ScreenUpdating = False
    Dim a As Long, b As Long, i As Long, dic As Object, arr, lr As Long, s As String, dk As String, kq, data, T, k As Long, c As Long
    Set dic = CreateObject("scripting.dictionary")
    With Sheets("data")
         lr = .Range("D" & Rows.Count).End(xlUp).Row
         arr = .Range("D2:J" & lr).Value
         For i = 1 To UBound(arr)
             dk = UCase(arr(i, 6))
             If Not dic.exists(dk) Then
                dic.Add dk, "#" & i
             Else
                dic.Item(dk) = dic.Item(dk) & "#" & i
             End If
         Next i
    End With
    With Sheets("DS")
         a = .Range("s5").Value - 1
         b = .Range("s6").Value - 1
    End With
    If a > b Then MsgBox "nhap so sai": Exit Sub
    If b > dic.Count Then MsgBox "qua lon": Exit Sub
    data = dic.keys
    With Sheets("DS")
         For i = a To b
             c = 0
             s = dic.Item(data(i))
             T = Split(s, "#")
             ReDim kq(1 To UBound(T), 1 To 4)
             For k = 1 To UBound(T)
                 c = c + 1
                 kq(c, 1) = c
                 kq(c, 2) = arr(T(k), 2)
                 kq(c, 3) = arr(T(k), 3)
                 kq(c, 4) = arr(T(k), 6)
             Next k
             .Range("A15:D999").ClearContents
             .Rows("15:999").EntireRow.Hidden = False
             If c Then
                .Range("A15:D15").Resize(c).Value = kq
                .Rows(c + 15 & ":999").EntireRow.Hidden = True
             End If
             .PrintOut
             '.PrintPreview
         Next i
   End With
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Bạn thử.
Mã:
Sub innhanh()
Application.ScreenUpdating = False
    Dim a As Long, b As Long, i As Long, dic As Object, arr, lr As Long, s As String, dk As String, kq, data, T, k As Long, c As Long
    Set dic = CreateObject("scripting.dictionary")
    With Sheets("data")
         lr = .Range("D" & Rows.Count).End(xlUp).Row
         arr = .Range("D2:J" & lr).Value
         For i = 1 To UBound(arr)
             dk = UCase(arr(i, 6))
             If Not dic.exists(dk) Then
                dic.Add dk, "#" & i
             Else
                dic.Item(dk) = dic.Item(dk) & "#" & i
             End If
         Next i
    End With
    With Sheets("DS")
         a = .Range("s5").Value - 1
         b = .Range("s6").Value - 1
    End With
    If a > b Then MsgBox "nhap so sai": Exit Sub
    If b > dic.Count Then MsgBox "qua lon": Exit Sub
    data = dic.keys
    With Sheets("DS")
         For i = a To b
             c = 0
             s = dic.Item(data(i))
             T = Split(s, "#")
             ReDim kq(1 To UBound(T), 1 To 4)
             For k = 1 To UBound(T)
                 c = c + 1
                 kq(c, 1) = c
                 kq(c, 2) = arr(T(k), 2)
                 kq(c, 3) = arr(T(k), 3)
                 kq(c, 4) = arr(T(k), 6)
             Next k
             .Range("A15:D999").ClearContents
             .Rows("15:999").EntireRow.Hidden = False
             If c Then
                .Range("A15:D15").Resize(c).Value = kq
                .Rows(c + 15 & ":999").EntireRow.Hidden = True
             End If
             .PrintOut
             '.PrintPreview
         Next i
   End With
Application.ScreenUpdating = True
End Sub
cảm ơn bạn nhiều lắm, mình đỡ cực nhiều lắm luôn, cảm ơn bạn
 
Upvote 0
Web KT

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

Back
Top Bottom