0

I have been experiencing an issue with VBA in Excel, where the Sub below will suddenly stop executing at the lines indicated.

The purpose of the sub is to update two cells whenever the "ckbRequestNeu" checkbox on the worksheet is pressed. However, when stepping through, the code only ever gets as far as writing a single value to the worksheet. E.g. if Inp_Exists = 1 then it will write Inp_Exists = 2, but will then immediately stop as if an End statement had executed.

If I then press F8 to continue stepping, the sub restarts as if the checkbox has been clicked again. This seems as if the ckbRequestNEU_Click event has been triggered again, but I've got no idea how this is happening.

Private Sub ckbRequestNEU_click()

    With Worksheets("Stress Requests")

        'If an input file exists, mark it as out of date
        If .Range("InpExists").Value = 1 Then
            .Range("InpExists").Value = 2  'Code stops here
        End If

        If .ckbRequestNEU = False Then
            .Range("Request_NEU") = 0   'And here
            .ckbRequestNEU.BackColor = RGB(179, 255, 179)
        Else
            .Range("Request_NEU") = 1   'Or here
            Sheets("Stress Requests").Cells(33, 5) = 1
            .ckbRequestNEU.BackColor = RGB(0, 204, 0)
        End If

    End With

End Sub

The program overall is to create an text input file for a finite element solver, and so the first If statement checks whether the file exists and marks it as out of date, based on the fact the checkbox (one of the parameters for the file) has changed.

  • Try tapping Ctrl-Break three times. I’ve seen code randomly stop before, this seems to get it going again. – wallyeye Jan 10 '19 at 12:18
  • I tried this, unfortunately I still get the same result. It's a really strange one and it only seems to happen when the code gets to a point where it is writing to a cell - I tried commenting out the lines where it stops and it will step through to the end of the sub as normal. – R Heward-Mills Jan 10 '19 at 13:15
  • https://stackoverflow.com/questions/40343021/macro-stopping-without-breakpoint Look at the answer in this thread. I've had a similar account as what wallyeye reported. Seems like ghost break points. This shouldn't be the case, but have you tried populating the cells with strings? E.g. ...Value = "2" – Tim Stack Jan 10 '19 at 13:54

0 Answers0