Mình mới viết code áp dụng cho file này các bạn xem giúp mình nha:
Sub tong_subtotal()
Dim lr As Long
lr = Sheet2.Cells(Rows.Count, 1).End(xlUp).Row
Sheet2.Range("v4").Formula = "=subtotal(9,v7
" & lr & ")"
Sheet2.Range("w4").Formula = "=subtotal(9,w7:w" & lr & ")"
End Sub
Sub Dien_cong_Thuc()
Dim lr As Long
lr = Sheet2.Cells(Rows.Count, 1).End(xlUp).Row
Dim a As Integer
Dim b As Integer
Dim c As Integer
Sheet2.Range("a1").Formula = "=COUNTA(G:G)"
a = Sheet2.Range("a1").Value + 5
Sheet2.Range("a2").Formula = "=COUNTA(r:r)"
b = Sheet2.Range("a2").Value + 5
If a - b <> 0 Then
c = b + 1
Sheet2.Range("j" & b).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.AutoFill Destination:=Range(Cells(b, 10), Cells(lr, 25))
Sheet2.Range("t" & c).Select
ActiveCell.FormulaR1C1 = "131"
Range(Selection, Selection.End(xlDown)).Select
Selection.FillDown
Else
MsgBox "Da copy du lieu"
Exit Sub
End If
End Sub