Hello,

I have a strange situation happening with a code (following). The macro hide/unhide a certain number of rows and checkboxes contained in the same range according to the value specified in a specific cell (that calls the macro itself on change).

Sub DEF_NoSTAZ_POS1()
Application.ScreenUpdating = False
Dim ActVAL As Integer
ActVAL = ActiveCell.Value
Range("A6:A70").EntireRow.Hidden = False
If ActVAL > ActiveCell.Offset(-2, 3).Value Then
ActiveCell.Offset(2, -13).Range("a1:a61").Select
Else
Select Case ActVAL
Case 0
ActiveCell.Offset(2, -13).Range("a1:a61").Select
Case 1
ActiveCell.Offset(8, -13).Range("a1:a55").Select
Case 2
ActiveCell.Offset(14, -13).Range("a1:a49").Select
Case 3
ActiveCell.Offset(20, -13).Range("a1:a43").Select
Case 4
ActiveCell.Offset(26, -13).Range("a1:a37").Select
Case 5
ActiveCell.Offset(32, -13).Range("a1:a31").Select
Case 6
ActiveCell.Offset(38, -13).Range("a1:a25").Select
Case 7
ActiveCell.Offset(44, -13).Range("a1:a19").Select
Case 8
ActiveCell.Offset(50, -13).Range("a1:a13").Select
Case 9
ActiveCell.Offset(56, -13).Range("a1:a7").Select
Case 10
ActiveCell.Offset(62, -13).Select
End Select
End If
Selection.EntireRow.Hidden = True
Dim Ctrl As Shape
For Each Ctrl In ActiveSheet.Shapes
If Not Intersect(Ctrl.TopLeftCell, Range(Selection.EntireRow.Address)) Is Nothing Then
Ctrl.Visible = False
End If
Next Ctrl
Selection.Offset(-1, 0).Select
Range(ActiveCell, ActiveCell.End(xlUp)).Select
For Each Ctrl In ActiveSheet.Shapes
If Not Intersect(Ctrl.TopLeftCell, Range(Selection.EntireRow.Address)) Is Nothing Then
Ctrl.Visible = True
End If
Next Ctrl
Selection.Offset(-1, 0).Select
ActiveCell.Offset(3, 13).Select
Application.ScreenUpdating = True
End Sub

The strange thing that happens, is that when it runs, it goes in debugging mode highlighting the line in red, but actually doing what it is meant to do.
I checked that if debugging mode is stopped, the code keeps working perfectly if going from high case values to lower (by debugging every time). On the other hand, when it goes from low case values to higher, it only works partially, unhiding the specific rows, but not unhiding the respective checkboxes, stopping on the same line of the code.

I know the code works, because before I didn't have this issue so often (it was happening just now and again, and after a reload of the excel file, it kept working). The only change I made to the file is the modality the user changes the value of the target cells. Indeed before he was meant to add directly a number in it, after the change he can choice between a certain set of numbers (according to other checks in the workbook).

Any idea why it does this?
And, how can I solve it?

I saw on the forum that maybe inserting a time wait gap, it might work. What is the connection? I'd like to understand. Otherwise, is there a way to prevent the code entering the debug mode (like skipping to the next instruction of the code)?

Thanks to anyone that may be interested in the problem.
Raf