tuyettrang186
Thành viên mới
- Tham gia
- 11/12/10
- Bài viết
- 30
- Được thích
- 4
Sub Worksheet_Activate()
Dim nN As Long
nN = S1.[A7].SpecialCells(xlLastCell).Row - 6
S2.[A4:D1000].ClearContents
S2.[B4].Resize(nN, 2).Value = S1.[B7].Resize(nN, 2).Value
S2.[D4].Resize(nN).Value = S1.[F7].Resize(nN).Value
S2.[A4].Resize(nN).FormulaR1C1 = "=MAX(R3C1:R[-1]C)+1"
S2.[A4].Resize(nN).Value = S2.[A4].Resize(nN).Value
End Sub
Nếu muốn vậy (Có chứa cả những dòng rỗng) bạn thay code sau:
Mã:Sub Worksheet_Activate() Dim nN As Long nN = S1.[A7].SpecialCells(xlLastCell).Row - 6 S2.[A4:D1000].ClearContents S2.[B4].Resize(nN, 2).Value = S1.[B7].Resize(nN, 2).Value S2.[D4].Resize(nN).Value = S1.[F7].Resize(nN).Value S2.[A4].Resize(nN).FormulaR1C1 = "=MAX(R3C1:R[-1]C)+1" S2.[A4].Resize(nN).Value = S2.[A4].Resize(nN).Value End Sub
Sub Worksheet_Activate()
Dim Rng As Range
Application.ScreenUpdating = False
S2.[A4:D1000].ClearContents
With S1
.Range("A6:F1000").AutoFilter Field:=2, Criteria1:="<>"
Set Rng = .AutoFilter.Range.Offset(1, 1).Resize(.AutoFilter.Range.Rows. _
Count - 1, 2).SpecialCells(xlCellTypeVisible)
Rng.Copy S2.[B4]
Set Rng = .AutoFilter.Range.Offset(1, 5).Resize(.AutoFilter.Range.Rows. _
Count - 1, 1).SpecialCells(xlCellTypeVisible)
Rng.Copy S2.[D4]
.Range("A6:F81").AutoFilter
End With
Set Rng = S2.[A4].Resize(WorksheetFunction.CountA(S2.[B4:B1000]))
Rng.FormulaR1C1 = "=MAX(R3C1:R[-1]C)+1"
Rng.Value = Rng.Value
Set Rng = Nothing
End Sub