NH_DK
Let's patience
- Tham gia
- 29/7/10
- Bài viết
- 865
- Được thích
- 1,203
- Nghề nghiệp
- Kế toán
A/C sửa dùm em code này nhé: Em muốn khi nhấn vào nút Tạo sổ thì nó tự động copy toàn bộ dữ liệu bên Sheet DATA sang (cả định dạng).
File đính kèm
PHP:
Option Explicit
Sub loc1()
Application.ScreenUpdating = False
Dim r, r1, n, i As Long, Ctu, tk As String
Sheet7.Range("A12:H56536").ClearContents
r1 = 12
With Sheet7
tk = Trim(.[f4])
For r = 12 To Sheet2.[A65536].End(xlUp).Row
If Trim(Sheet2.Cells(r, 6)) = tk Then
Sheet2.Cells(r, 1).Resize(, 5).Copy .Cells(r1, 1)
.Cells(r1, 5) = Sheet2.Cells(r, 7)
.Cells(r1, 6) = Sheet2.Cells(r, 8)
r1 = r1 + 1
ElseIf Trim(Sheet2.Cells(r, 7)) = tk Then
Sheet2.Cells(r, 1).Resize(, 4).Copy .Cells(r1, 1)
.Cells(r1, 5) = Sheet2.Cells(r, 6)
.Cells(r1, 7) = Sheet2.Cells(r, 8)
r1 = r1 + 1
End If
Next
n = .Range("D65000").End(xlUp).Row
.Range("D" & n + 1) = .Range("B11")
.Range("D" & n + 2) = .Range("C11")
.Range("F" & n + 1 & ":G" & n + 1) = "=SUM(R12C:R" & n & "C)"
.Range("F" & n + 2) = "=MAX(F11+F" & n + 1 & "-G11-G" & n + 1 & ",0)"
.Range("G" & n + 2) = "=MAX(G11+G" & n + 1 & "-F11-F" & n + 1 & ",0)"
For i = 13 To n
If .Range("B" & i) = .Range("B" & i - 1) Then
.Range("A" & i & ":C" & i).ClearContents
End If
Next
End With
n = [A65500].End(xlUp).Row + 4 ' em dat n ở đây được ko?
Range("A" & n & ":I" & n + 20).ClearContents
With Cells(n - 1, "B").Offset(2, 0)
.FormulaR1C1 = "=NgGhi": .Font.Bold = True
.Font.Name = "Times New Roman": .Font.Size = 13
.HorizontalAlignment = xlCenter
End With
With Cells(n - 1, "B").Offset(3, 0)
.FormulaR1C1 = "=Ky": .Font.Italic = True
.Font.Name = "Times New Roman": .Font.Size = 12
.HorizontalAlignment = xlCenter
End With
With Cells(n - 1, "D").Offset(3, 0)
.FormulaR1C1 = "=Ky": .Font.Italic = True
.Font.Name = "Times New Roman": .Font.Size = 12
.HorizontalAlignment = xlCenter
End With
With Cells(n - 1, "D").Offset(2, 0)
.FormulaR1C1 = "=KTT": .Font.Bold = True
.Font.Name = "Times New Roman": .Font.Size = 13
.HorizontalAlignment = xlCenter
End With
With Cells(n - 1, "G").Offset(3, 0)
.FormulaR1C1 = "=Ky2": .Font.Italic = True
.Font.Name = "Times New Roman": .Font.Size = 12
.Font.Name = "Times New Roman": .HorizontalAlignment = xlCenterAcrossSelection
End With
With Cells(n - 1, "G").Offset(2, 0)
.FormulaR1C1 = "=GD": .Font.Bold = True
.Font.Name = "Times New Roman": .Font.Size = 13
.Font.Name = "Times New Roman": .HorizontalAlignment = xlCenterAcrossSelection
End With
Application.ScreenUpdating = True
End Sub
File đính kèm