Results 1 to 22 of 22

Conditionally Hide Columns

Threaded View

  1. #1
    Forum Contributor
    Join Date
    09-19-2004
    Location
    Canada
    Posts
    408

    Question Conditionally Hide Columns

    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
    Last edited by Gos-C; 03-23-2010 at 01:18 PM.
    Using Excel 2010 & Windows 10
    "It is better to be prepared for an opportunity and not have one than to have an opportunity and not be prepared."

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1