Hi Folks,
I have the following workbook sample that includes the code below, the code when run from the project window works a treat, however when it's run via the button on the welcome sheet, its results are varied.
I have tried the old caveat of "run it on a different machine" where the results are still as described above.
Any and all assistance is appreciated
Iain
Public Sub Hide_Weeks()
'http://www.excelforum.com/excel-programming/785512-conditional-column-hide.html
Dim wb As Workbook
Dim ws As Worksheet
Dim Ans As Integer
Dim ReadyAns As Integer
Dim i As Integer
With Application
.DisplayAlerts = False
.EnableEvents = False
.ScreenUpdating = False
End With
Set wb = ActiveWorkbook ' Define the active workbook
ReadyAns = Sheets("Welcome").Range("B2").Value - 1 ' Give last week as the default to start hiding sheets
Ans = Val(InputBox("Enter last week to hide.", "WEEKS TO HIDE", ReadyAns, , 100))
For Each ws In Worksheets
Select Case ws.Name
Case "Welcome", "CRM Data", "GP Data", "Properties" ' These sheets we do not want any rows hidden
With ws
ws.Columns("A:BK").EntireColumn.Hidden = False
Range("A1").Select
End With
Case Else
With ws
ws.Columns("A:BB").EntireColumn.Hidden = False
For i = 1 To 53
If Cells(2, 2).Offset(0, i - 1) <= Ans Then
ws.Cells(2, 2).Offset(0, i - 1).EntireColumn.Hidden = True
ElseIf ws.Columns(i + 1).Hidden = True Then
Cells(2, 2).Offset(0, i - 1).EntireColumn.Hidden = False
End If
Next i
End With
End Select
Next ws
With Application
.DisplayAlerts = True
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub
Bookmarks