VBA Debugging – Video

I have decided to make a 19 minute YouTube video, to explain the basics of VBA debugging, as there are quite a few tricks that not everyone knows.

The agenda:

  • Properties Window -> F4
  • Immediate Window -> Ctrl + G
  • Project Window -> Ctrl + R
  • Run -> F5
  • Run Step by step -> F8
  • Run to cursor -> Ctrl + F8
  • Putting a stop -> F9
  • Removing all stops -> Ctrl + Shift + F9
  • Bookmarks
  • Jump away function -> Ctrl + Shift + F8
  • Jumping over function -> Shift + F8
  • Watch Window -> Shift + F9
  • Go to definition of the declared function -> Shift + F2
  • Go to previous cursor -> Ctrl + Shift + F2
  • Get parameter info -> Ctrl + i

The code:

Sub Main()

    Dim a As Long
    Dim b As Long
    
    a = 6
    b = Fibonacci(a)
    Debug.Print b
    
    b = Fibonacci(a + a)
    Debug.Print b

End Sub

Function Fibonacci(counter As Long) As Long

    Dim f1 As Long
    Dim f2 As Long
    
    f1 = 1
    f2 = 1
    
    Dim result As Long
    result = 0
    
    Dim i As Long
    i = 2

    While i < counter
        result = f1 + f2
        f1 = f2
        f2 = result
        i = i + 1
    Wend
    
    Fibonacci = result

End Function

Enjoy it! 🙂