Hi all,
I am trying to hide all unnecessary columns to aid in the data entry process.
The data entry section is A4:CY1504.
For each record, column D would have one of several codes (CM, LR, MG, NR, etc.), and column Q would have one of several reasons (Excessive time charges, Failure to produce documentation, Not an eligible benefit, Overcharged, etc.) - drop-down lists.
When the user selects/enters either “CM”, “LR”, “MG” or “NR”, I want to hide columns U:AI, AP:BJ and BQ:CQ.
Then, for the same record, if the user selects/enters:
“Excessive time charges”, I want to hide columns AM:BP
“Failure to produce documentation”, I want to hide columns AJ:AL and BK:BP
“Not an eligible benefit”, I want to hide columns AJ:AO and BN:BP
“Overcharged”, I want to hide columns AJ:BM
When the user selects/enters any other code in column D, I want to hide columns U:CQ.
When the user saves the file or enters anything in column C, I want to unhide all columns.
So far, I have the following:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Target.Column <> 4 Then Exit Sub 'only works in Columns D
If Target.Count > 1 Then Exit Sub
If Intersect(Target, Cells(4, 4)) Is Nothing Then Exit Sub
ActiveSheet.Protect Password:="test", userinterfaceonly:=True
Cells.Columns.Hidden = False
Select Case Cells(4, 4).Value
Case "CM", “LR”, “MG”, “NR”
Columns("U:AI").Hidden = True
Columns("AP:BJ").Hidden = True
Columns("BQ:CQ").Hidden = True
End Select
Select Case Cells(4, 17).Value
Case "Excessive time charges"
Columns("AM:BP").Hidden = True
Case "Failure to produce documentation"
Columns("AJ:AL").Hidden = True
Columns("BK:BP").Hidden = True
Case "Not an eligible benefit"
Columns("AJ:AO").Hidden = True
Columns("BN:BP").Hidden = True
Case "Overcharged"
Columns("AJ:BM").Hidden = True
Case Else
Columns("U:CQ").Hidden = True
End Select
End Sub
However, it is not working.
Any help, please?
Thank you,
Gos-C
Bookmarks