Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, [D18]) Is Nothing Then
Dim Sh As Worksheet, Rng As Range, sRng As Range, Clls As Range
Dim Col As Byte
Set Sh = Sheets("Sheet2"): Sheets("vd").Select
Set Rng = Sh.Range("LyTrinh").Find([D18].Value, , xlFormulas, xlWhole).Offset(, 3)
Set sRng = Sh.Range(Rng, Sh.Cells(Rng.Row, "IV").End(xlToLeft))
Set Rng = Union(sRng.SpecialCells(xlCellTypeConstants, 3), _
sRng.SpecialCells(xlCellTypeFormulas, 3))
[B23].Resize(30, 8).ClearContents
For Each Clls In Rng
Col = Clls.Column
With [B99].End(xlUp).Offset(1)
.Value = Sh.Cells(2, Col).Value
.Offset(, 1).Value = Sh.Cells(6, Col).Value
.Offset(, 2).Value = Clls.Value
End With
Next Clls
End If
End Sub
Thi với sư phụ!PHP:Option Explicit Private Sub Worksheet_Change(ByVal Target As Range) If Not Intersect(Target, [D18]) Is Nothing Then Dim Sh As Worksheet, Rng As Range, sRng As Range, Clls As Range Dim Col As Byte Set Sh = Sheets("Sheet2"): Sheets("vd").Select Set Rng = Sh.Range("LyTrinh").Find([D18].Value, , xlFormulas, xlWhole).Offset(, 3) Set sRng = Sh.Range(Rng, Sh.Cells(Rng.Row, "IV").End(xlToLeft)) Set Rng = Union(sRng.SpecialCells(xlCellTypeConstants, 3), _ sRng.SpecialCells(xlCellTypeFormulas, 3)) [B23].Resize(30, 8).ClearContents For Each Clls In Rng Col = Clls.Column With [B99].End(xlUp).Offset(1) .Value = Sh.Cells(2, Col).Value .Offset(, 1).Value = Sh.Cells(6, Col).Value .Offset(, 2).Value = Clls.Value End With Next Clls End If End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Sh As Worksheet
If Not Intersect(Target, [D4]) Is Nothing Then
Range("A9:E10000").ClearContents
Set Sh = Sheets("Sheet2")
On Error GoTo ExitSub
With Sh.Range("LyTrinh").Find([D4].Value, , , xlWhole)
Range("D5").Value = .Offset(, 1).Value
Range("D6").Value = .Offset(, 2).Value
With .Offset(, 3).Resize(, Sh.Range("VatTu").Columns.Count)
.SpecialCells(2).Copy: Range("D9").PasteSpecial 3, , , True
Intersect(.SpecialCells(2).EntireColumn, Sh.Range("VatTu").Resize(2)).Copy
Range("B9").PasteSpecial 3, , , True
End With
End With
With Range([B9], [B65536].End(xlUp))
.Offset(, -1).Value = Evaluate("ROW(R:R)")
End With
Target.Select
Application.CutCopyMode = False
End If
ExitSub:
End Sub
---Thi với sư phụ!
Em dùng PasteSpecial\Transpose ---> Khỏi vòng lập!
PHP:Private Sub Worksheet_Change(ByVal Target As Range) Dim Sh As Worksheet If Not Intersect(Target, [D4]) Is Nothing Then Range("A9:E10000").ClearContents Set Sh = Sheets("Sheet2") On Error GoTo ExitSub With Sh.Range("LyTrinh").Find([D4].Value, , , xlWhole) Range("D5").Value = .Offset(, 1).Value Range("D6").Value = .Offset(, 2).Value With .Offset(, 3).Resize(, Sh.Range("VatTu").Columns.Count) .SpecialCells(2).Copy: Range("D9").PasteSpecial 3, , , True Intersect(.SpecialCells(2).EntireColumn, Sh.Range("VatTu").Resize(2)).Copy Range("B9").PasteSpecial 3, , , True End With End With With Range([B9], [B65536].End(xlUp)) .Offset(, -1).Value = Evaluate("ROW(R:R)") End With Target.Select Application.CutCopyMode = False End If ExitSub: End Sub
Đúng rồi anh à! Vì em dựa trên file của sư phụ, name có sẳn---
Cho anh hỏi: có 2 name hả chú?
---Đúng rồi anh à! Vì em dựa trên file của sư phụ, name có sẳn
Với dử liệu khác, ta sửa lại tham chiếu của 2 name này là được
--------------------------
Bài này còn 1 chiêu nữa không dùng Find ---> Ta dùng AutoFilter lọc dử liệu theo điều kiện tại Validation, xong ta copy 1 phát 1 toàn bộ (nhưng cell có dữ liệu) rồi Paste special\Transpose là xong
....ra chiêu đi chú (để ...học lóm chứ)Bài này còn 1 chiêu
Name động dể mà anh, chẳng hạn---
Dữ liệu thì luôn cập nhật => cho name nó"động đậy" đi chú.
....ra chiêu đi chú (để ...học lóm chứ)
LyTrinh =OFFSET(Sheet2!$B$4,,,COUNTA(Sheet2!$B$4:$B$10000),)