How to check which line of VBA code is causing errors
To check which line is giving you the error, you can use the ERL
property. See this sample code below.
Sub sample()Dim i As LongOn Error GoTo Whoa10 Debug.Print "A"20 Debug.Print "B"30 i = "Sid"40 Debug.Print "A"50 Exit SubWhoa: MsgBox "Error on Line : " & ErlEnd Sub
For this to work, you will have to number the code lines as I have done above. Run the above code and see what happens.
Sub Main() Dim lNum As Long On Error GoTo ErrHandler lNum = 1 / 0ErrExit: Exit SubErrHandler: Debug.Print Err.Description Stop ResumeEnd Sub
When you get to Stop, then Step Into twice. If you don't have F8, you should have a menu item for stepping into a line. Resume will take you back to the line that caused the error.