This solution utlizes the current state of sheet to determine what to hide next ... i.e. if no columns hidden then hide all but Column A , if Column is only Visible Then hide all but Column B... etc etc ... and if any errors occur then show all columns. A few of the nice things about this solution is that there is no extra coding for adding new columns to your "hide cycle " all you need to do is modify the variable "MaxColToHide = 26" . A second benifit is that this cycle will continue from where you left off the last time the book was used... even if it hasn't been used for months.
Please try and let me know what you think ... cheers
Public Sub HideColumnBySequence()
On Error GoTo ShowAll
Dim ColToShow As Long
Dim MaxColToHide As Long
' CONFIGURE how far up to cycle the column Hide here !
MaxColToHide = 26
With Rows("1:1").Cells
If .SpecialCells(xlCellTypeVisible).Count = .Cells.Count Then
ColToShow = 1
Else
For Col = 1 To MaxColToHide
ColToShow = all
If Cells(1, Col).EntireColumn.Hidden = False Then
ColToShow = Col + 1
GoTo Hide
End If
Next Col
End If
End With
Hide:
Cells.EntireColumn.Hidden = True
Cells(1, ColToShow).EntireColumn.Hidden = False
Cells(1, ColToShow).EntireColumn.Select
Exit Sub
ShowAll:
Cells.EntireColumn.Hidden = False
End Sub
Bookmarks