Đây là code của file Tim_no (trên diễn đàn), em có sử dụng và tăng hêm nhiều cột dữ liệu. Nhưng với dữ liệu khỏang trên 30 cột, thì có cách nào rút gọn lại được không.
Rút gọn lại từ 1>6
Mã:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim dong1, dong2
Dim gia_tri
If Target.Row = 2 And Target.Column = 3 Then
dong1 = 5
dong2 = 5
gia_tri = Target.Value
Sheets("out_put").Range("B5:G100").Clear
Do While Len(Trim(Sheets("in_put").Cells(dong1, 2).Value)) > 0
If Sheets("in_put").Cells(dong1, 2).Value = gia_tri Then
1/ Sheets("out_put").Cells(dong2, 2).Value = Sheets("in_put").Cells(dong1, 2).Value
2/ Sheets("out_put").Cells(dong2, 3).Value = Sheets("in_put").Cells(dong1, 3).Value
3/ Sheets("out_put").Cells(dong2, 4).Value = Sheets("in_put").Cells(dong1, 4).Value
4/ Sheets("out_put").Cells(dong2, 5).Value = Sheets("in_put").Cells(dong1, 5).Value
5/ Sheets("out_put").Cells(dong2, 6).Value = Sheets("in_put").Cells(dong1, 6).Value
6/ Sheets("out_put").Cells(dong2, 7).Value = Sheets("in_put").Cells(dong1, 7).Value
dong2 = dong2 + 1
End If
dong1 = dong1 + 1
Loop
End If
End Sub
Chỉnh sửa lần cuối bởi điều hành viên: