Hide Columns in Sheet 2 based on data change in sheet 1

  • Hi All,
    After much searching and trying various code snippets, I am unable to solve my problem of why this code is not working. There are 2 sheets on the worksheet. If the value in cell A1 Sheet 1 = 0 then hide Column C in Sheet 2. Seems simple. I am using Excel for Mac 2016. Any advice appreciated. Cheers and happy Easter to all. Jan
    Worksheet is attached and code is in Sheet1


    [VBA]Private Sub Worksheet_Change(ByVal Target As Range)
    If Target_Address = Range("A1") Then
    If Target_Address = "0" Then
    Sheet2.Columns("C").EntireColumn.Hidden = True
    Else
    Sheet2.Columns("C").EntireColumn.Hidden = False
    End If
    End Sub[/VBA]

  • Try this

    Code
    Private Sub Worksheet_Change(ByVal Target As Range)
    
    
        If Not Intersect(Target, [a1]) Is Nothing Then
            Sheet2.Columns(3).Hidden = 0
            If Target = 0 Then Sheet2.Columns(3).Hidden = 1
        End If
    
    
    End Sub

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

  • Thanks KjBox for the really prompt solution. Fantastic. Worked perfectly. :) I did read about the Intersect but thought it related to a range of cells.
    I had modified my code based on someone else's solution so not sure why it worked for them and not me. (I did miss an "EndIf on my post"..still didn't work though).
    Happy Easter.
    Jan

  • You're welcome.

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!