Hi there, in the attached spreadsheet there are a whole bunch of animals across the top row. What I want is a macro that will hide the columns of a cell that equal certain animals. So for example I want a macro that will hide the columns if the value in the top row of that column equals albatros, pelican and aligator. At the moment I am using this painful macro but it isn't efficient as I need to copy and paste each code statement for each column, which is insane:
--------------------------
Sub HideCol()
If Range("A1") = "albatros" Or Range("A1") = "pelican" Or Range("A1") = "aligator" Then
Columns("A:A").Select
Selection.EntireColumn.Hidden = True
If Range("B1") = "albatros" Or Range("B1") = "pelican" Or Range("B1") = "aligator" Then
Columns("B:B").Select
Selection.EntireColumn.Hidden = True
End If
End Sub
--------------------------
And this only does 2 columns and this just isn't flexible if I want to do heaps of columns or if I want to change an animal.
Thanks for your support in advance, much appreciated!
hide column.xlsx
Bookmarks