
Originally Posted by
titovalle
Hello friends,
This is my first post and I think this forum has really brilliant people cooperating.
My inquirie is that I would like to create a macro in excel that can hide and unhide columns automatically when a cell value changes.
ie. When A1=pizza hide column d and show column c
When A1=burger hid column c and show column d
I want to apply this macro to a file that contains a lot of columns for each type of information.
I will appreciate any help I can get about this.

Hi,
In the worksheet tab, rightmouse and View Code, and paste this into that sheet
Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_Range As String = "A1:A1"
If Not Intersect(Target, Me.Range(WS_Range)) Is Nothing Then
Application.EnableEvents = False
Application.ScreenUpdating = False
On Error Resume Next
With ActiveSheet
If Cells(1, 1).Value = "burger" Then
Cells(1, 3).EntireColumn.Hidden = True
Cells(1, 4).EntireColumn.Hidden = False
ElseIf Cells(1, 1).Value = "pizza" Then
Cells(1, 4).EntireColumn.Hidden = True
Cells(1, 3).EntireColumn.Hidden = False
Else: Cells(1, 3).EntireColumn.Hidden = False
Cells(1, 4).EntireColumn.Hidden = False
End If
End With
Application.EnableEvents = True
Application.ScreenUpdating = True
End If
On Error GoTo 0
End Sub
---
Bookmarks