Em võ vẽ ko biết VBA là gì đâu ạ. Nhờ các thầy, các bạn gia tay giúp em TH này ạ.
Em muốn unhide hoặc hide một số cột nằm ngoài chu kì tính lương của em.
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect([b4], Target) Is Nothing Then
Dim Dat As Date, Dauthang As Date, Cuoithang As Date
Dim Ww As Byte
Dim hRng As Range, Clls As Range
HideColumns Target: Range([g17], [an17]).Clear
Dat = Target.Value: Dauthang = DateSerial(Year(Dat), 1, 1)
Cuoithang = DateSerial(Year(Dat), 12, 31)
For Each Clls In Range([g19], [g19].End(xlToRight))
If Clls < Dauthang Or Clls > Cuoithang Then
If hRng Is Nothing Then
Set hRng = Clls.EntireColumn
Else
Set hRng = Union(hRng, Clls.EntireColumn)
End If
End If
If Clls = Dauthang Then Clls.Offset(-3) = Dat
Next Clls
hRng.Select
HideColumns hRng, False
End If
End Sub
Sub HideColumns(Rng As Range, Optional AllCols As Boolean = True)
If AllCols Then
Cells.Select
Selection.EntireColumn.Hidden = False
Else
Rng.EntireColumn.Hidden = True
End If
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect([b4], Target) Is Nothing Then
HideColumns Target
[b5].Select
End If
End Sub
Em muốn unhide hoặc hide một số cột nằm ngoài chu kì tính lương của em.
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect([b4], Target) Is Nothing Then
Dim Dat As Date, Dauthang As Date, Cuoithang As Date
Dim Ww As Byte
Dim hRng As Range, Clls As Range
HideColumns Target: Range([g17], [an17]).Clear
Dat = Target.Value: Dauthang = DateSerial(Year(Dat), 1, 1)
Cuoithang = DateSerial(Year(Dat), 12, 31)
For Each Clls In Range([g19], [g19].End(xlToRight))
If Clls < Dauthang Or Clls > Cuoithang Then
If hRng Is Nothing Then
Set hRng = Clls.EntireColumn
Else
Set hRng = Union(hRng, Clls.EntireColumn)
End If
End If
If Clls = Dauthang Then Clls.Offset(-3) = Dat
Next Clls
hRng.Select
HideColumns hRng, False
End If
End Sub
Sub HideColumns(Rng As Range, Optional AllCols As Boolean = True)
If AllCols Then
Cells.Select
Selection.EntireColumn.Hidden = False
Else
Rng.EntireColumn.Hidden = True
End If
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect([b4], Target) Is Nothing Then
HideColumns Target
[b5].Select
End If
End Sub