Hide a column, based on the value in other field

Thanks Thanks:  0
Likes Likes:  0
Results 1 to 4 of 4

Thread: Hide a column, based on the value in other field

  1. #1
    New Member
    Join Date
    Jul 2017
    Posts
    2
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Hide a column, based on the value in other field

     
    Hi ,

    I need a help to hide a column based on the value in other field in Excel.

    Below is my example:

    When i open my excel, I want to hide a Column 'I',
    If field "D3" has "0".
    Else Field "D3" has "1" can visible.

    I use below code , But it was working when i change the value in D3 field. But when i open the file itself need to hide.

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$D$3" And Target.Text = "0" Then
    Range("I:I").EntireColumn.Hidden = True
    Else
    If Target.Address = "$D$3" And Target.Value = "1" Then
    Range("I:I").EntireColumn.Hidden = False
    End If
    End If
    End Sub

    But it was working after changing the value in that field. Need to validate when its open.

    Thanks
    Venu

  2. #2
    MrExcel MVP Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    3,269
    Post Thanks / Like
    Mentioned
    67 Post(s)
    Tagged
    3 Thread(s)

    Default Re: Hide a column, based on the value in other field

    Hi & welcome to the board

    How about
    Code:
    Private Sub Workbook_Open()
    
        With Sheets("sheet1")
            If .Range("D3") = 1 Then
                .Columns(9).Hidden = False
            ElseIf .Range("D3") = 0 Then
                .Columns(9).Hidden = True
            End If
        End With
    
    End Sub
    Changing the sheet name to suit
    - Posting guidelines, forum rules and terms of use
    - Try searching for your answer first, see how
    - Read the FAQs
    - List of BB codes

    Running Office 2003 & 2013 on Win 7

  3. #3
    New Member
    Join Date
    Jul 2017
    Posts
    2
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up Re: Hide a column, based on the value in other field

    Quote Originally Posted by Fluff View Post
    Hi & welcome to the board

    How about
    Code:
    Private Sub Workbook_Open()
    
        With Sheets("sheet1")
            If .Range("D3") = 1 Then
                .Columns(9).Hidden = False
            ElseIf .Range("D3") = 0 Then
                .Columns(9).Hidden = True
            End If
        End With
    
    End Sub
    Changing the sheet name to suit
    Hi Fluff,

    Thank You!. Its working Great.

  4. #4
    MrExcel MVP Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    3,269
    Post Thanks / Like
    Mentioned
    67 Post(s)
    Tagged
    3 Thread(s)

    Default Re: Hide a column, based on the value in other field

      
    Glad to help & thanks for the feedback
    - Posting guidelines, forum rules and terms of use
    - Try searching for your answer first, see how
    - Read the FAQs
    - List of BB codes

    Running Office 2003 & 2013 on Win 7

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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

 

 
DMCA.com