Hide a column, based on the value in other field

Venubabu

New Member
Joined
Jul 17, 2017
Messages
2
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
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
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
 
Upvote 0
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.
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,213,561
Messages
6,114,317
Members
448,564
Latest member
ED38

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top