Forum Discussion
YlvaElise
Mar 17, 2023Copper Contributor
Run a macro
Hi all, I want to run a Macro. What I want it to do: When I select Intern, I want the file to show the yellow and blank columns, and when I select Extern, I want it to show the yellow and green c...
NikolinoDE
Mar 17, 2023Gold Contributor
For example, you can try this code 🙂
Sub Hide_Unhide_Columns()
Dim ws As Worksheet
Dim rng As Range
Dim cell As Range
Set ws = ThisWorkbook.Sheets("Sheet1") 'Change sheet name as needed
Set rng = ws.Range("A1:G1") 'Change range as needed For Each cell In rng
If cell.Value = "Intern" Then 'Change value as needed cell
.EntireColumn.Hidden = False 'Show column Else
If cell.Value = "Extern" Then 'Change value as needed cell
.EntireColumn.Hidden = False 'Show column Else cell
.EntireColumn.Hidden = True 'Hide column
End If
Next cell
End Sub
You need to customize the code to suit your needs and associate it with a button click or worksheet switch event.
I hope this helps you.