FizzBuzz in VBA. Takes start and end numbers as arguments. Will handle any pair of integers to +- 2 Billion or so, determine whether the sequence is increasing or decreasing and output numbers to the immediate window.
Public Sub PrintFizzBuzz(ByVal startNum As Long, ByVal endNum As Long)
Dim currentNum As Long
Dim stepValue As Long
Dim outputString As String
Dim isFizzBuzz As Boolean
If startNum <= endNum Then stepValue = 1 Else stepValue = -1
For currentNum = startNum To endNum Step stepValue
outputString = ""
isFizzBuzz = False
If currentNum Mod 3 = 0 Then
outputString = outputString & "Fizz"
isFizzBuzz = True
End If
If currentNum Mod 5 = 0 Then
outputString = outputString & "Buzz"
isFizzBuzz = True
End If
If Not isFizzBuzz Then outputString = CStr(currentNum)
Debug.Print outputString
Next currentNum
End Sub