Option Explicit
Private Sub CommandButton1_Click()
Dim Sh As Worksheet, Rng As Range, sRng As Range
Dim Code As Range, Clls As Range, rRng As Range
Dim eRw As Long, Jj As Long
Sheet1.Select: Set Sh = Sheet2
Set Rng = Sh.Range(Sh.[b1], Sh.[iv1].End(xlToLeft))
eRw = [A65500].End(xlUp).Row
Set Code = Sh.Range(Sh.[A2], Sh.Range("A" & Sh.[A65500].End(xlUp).Row + eRw))
'Cot Cua Ngày Càn Chép:'
Set sRng = Rng.Find([g1].Value, , xlFormulas, xlWhole)
If Not sRng Is Nothing Then
If Sh.Cells(65500, sRng.Column).End(xlUp).Row > sRng.Row Then
MsgBox "Da Nhap Roi!", , "GPE Xin Thong Bao:"
Exit Sub
End If
For Each Clls In Range([A3], [A65500].End(xlUp))
Set rRng = Code.Find(Clls.Value)
If Not rRng Is Nothing Then
Sh.Cells(rRng.Row, sRng.Column).Resize(, 4).Value = _
Clls.Offset(, 1).Resize(, 4).Value
Else
With Sh.[A65500].End(xlUp).Offset(1)
.Value = Clls.Value
Sh.Cells(.Row, sRng.Column).Resize(, 4).Value = _
Clls.Offset(, 1).Resize(, 4).Value
End With
End If
Next Clls
End If
End Sub