Mã:
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo out
Application.ScreenUpdating = False
Application.EnableEvents = False
If Target.Cells = [A1] Then
For i = 3 To 38
If Target.Cells.Value = "*" Or Target.Cells.Value > 12 Then
Cells(3, i).EntireColumn.Hidden = False
Target.Cells.Value = "*"
End If
If Target.Cells.Value <= 12 Then
If Cells(3, i) = Target.Cells.Value Or Cells(3, i) = Target.Cells.Value - 1 Then
Cells(3, i).EntireColumn.Hidden = False
Else: Cells(3, i).EntireColumn.Hidden = True
End If
End If
Next i
End If
out: Exit Sub
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
Em có viết code như trên để hide những tháng khác với yêu cầu, nhưng khi e copy hay xử lý dữ liệu với 1 range là nó exit sub luôn và ko return lại được nữa, mọi người có cách nào xử lý vấn đề này ko ạ