Hi,

I could not find the solution to this problem anywhere. I am building a worksheet, and one of the features it needs to do is to hide or unhide certain columns when a certain macro is triggered. I tried using a simple code below (which works in another workbook) but it behaves strangely in the workbook:

Sub Test2()                                        'line 1

Columns("B:AA").Select                               'line 2
If Selection.EntireColumn.Hidden = True Then       'line 3
    Selection.EntireColumn.Hidden = False          'line 4
End If                                              'line 5

Columns("B:AA").Select                                'line 6
If Selection.EntireColumn.Hidden = False Then      'line 7
    Selection.EntireColumn.Hidden = True           'line 8
End If                                              'line 9

End Sub                                            'line 10
When I use the debugger, and columns are initially hidden, the code will pass through lines 1-4. This results in unhiding the columns. However, the sub ends right then, and line 5 is never highlighted. If I click "F8" again, it goes to line 1. This time, when I keep clicking "F8", it reaches line 8, executes the code (hides the columns) and then exits the sub again. If I click "F8" again, it will go to line 1.

How can I fix it so that the code does not get cut off after executing a statement and continues with the rest of the macro?

Thank you!