Excel VBA Step Mode (F8) jumps to another VBA Function

JohnZ1156

Board Regular
Joined
Apr 10, 2021
Messages
160
Office Version
  1. 2021
Platform
  1. Windows
I have an Excel Workbook with many VBA macros. I also have a VBA function called SpellNumber that I got from an Excel Forum. (I don't remember if it was this forum or a different forum.).

The SpellNumber function works great to convert a numeric value into written text. Just like the amount on a check in text format.

My problem is that while I'm working on a completely different macro, having nothing to do with that function, if I test my macro in Single Step Mode, as I continue to press the <F8> function key, it jumps to this SpellNumber VBA function. I don't know why, but it's very annoying.

The SpellNumber function is in a module all by itself, and has the text, Options Explicit at the very beginning.

Can anyone please explain to me why this is happening, and PLEASE tell me how I can prevent <F8> from suddenly jumping to a completely different VBA script?

Thank you.
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Are you using the function Spellnumber in any cells/columns that you are selecting in your code that you are stepping through?
It would help if you post the code that you are stepping through with F8
 
Upvote 0
No, not using SpellNumber Function in any cells/columns within my code.
Here is the code.

VBA Code:
Sub DailyBalance()

    Dim var As Variant
    
    var = Range("Bank1!B15").Value
    Worksheets("Sheet1").Select
    Range("A11").End(xlDown).Select
    
    With Range(ActiveCell.Address)
        If Not IsDate(.Value) Then
        MsgBox "No date"
        ActiveCell.Offset(1, 0).Select

        ElseIf .Value = var Then
        MsgBox ("Date is already = " & var)
        'MsgBox "Date is today"
        ActiveCell.Offset(0, 1).Select
        GoTo Process:
        
        Else
        ActiveCell.Offset(1, 0).Select
        ActiveCell.Value = var
        ActiveCell.Offset(0, 1).Select
        GoTo Process:
        
        End If
    End With
Process:
    ActiveCell.FormulaR1C1 = "=Check_Balance"
    ActiveCell.Offset(0, 1).Select
    ActiveCell.FormulaR1C1 = "=Savings_Balance"
    ActiveCell.Offset(0, 1).Select
    ActiveCell.FormulaR1C1 = "=BankA_Balance"
    ActiveCell.Offset(0, 1).Select
    ActiveCell.FormulaR1C1 = "=BankB_Balance"
    ActiveCell.Offset(0, 1).Select
    ActiveCell.FormulaR1C1 = "=BankC_Balance"
    ActiveCell.Offset(0, 1).Select
    ActiveCell.FormulaR1C1 = "=Cash_Balance"
    ActiveCell.Offset(0, 1).Select
    ActiveCell.FormulaR1C1 = "=TRP_Balance"
    ActiveCell.Offset(0, 1).Select
    ActiveCell.FormulaR1C1 = "=FID_Balance"
    ActiveCell.Offset(0, -7).Select
    Range(ActiveCell.Offset(0, 0), ActiveCell.Offset(0, 7)).Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues
    ActiveCell.Offset(0, 8).Select
    ActiveCell.Offset(-1, 0).Select
    Selection.Copy
    ActiveCell.Offset(1, 0).Select
    Selection.PasteSpecial Paste:=xlPasteFormats
    Selection.PasteSpecial Paste:=xlPasteFormulas

    ActiveCell.Offset(0, -9).Select
    Application.CutCopyMode = False
    ActiveCell.Offset(-1, 0).Select
    Range(ActiveCell.Offset(0, 0), ActiveCell.Offset(0, 9)).Select
    Selection.Copy
    ActiveCell.Offset(1, 0).Select
    Range(ActiveCell.Offset(0, 0), ActiveCell.Offset(0, 9)).Select
    Selection.PasteSpecial Paste:=xlPasteFormats
    ActiveCell.Offset(1, 0).Select
    Application.CutCopyMode = False
    
    Application.Wait (Now + TimeValue("0:00:15"))
    
    Worksheets("Consolidation").Select
    Range("A1").Select
    Application.CutCopyMode = False
    
End Sub
 
Upvote 0
No, not using SpellNumber Function in any cells/columns within my code.
No, not are you using SpellNumber Function within the code, are you using it in any of the cells that your ranges and offsets refer to in the code as activating or selecting the cells could be triggering a recalculation of the formulas.

Also do you have the words Application.Volatile in the SpellNumber Function
 
Upvote 0
Hi Mark858,
Thank you for your help and I will try to answer your questions as best as I can.

As per your first question, No, I don't think nor can I identify any of the cells that my ranges and offsets refer to in the code as activating or selecting the cells could be triggering a recalculation of the formulas.

Second question: No, the words Application.Volatile are not in the SpellNumber Function

Here is the SpellNumber Function incase you'd like to see it.

VBA Code:
Option Explicit

'Main Function
Function SpellNumber(ByVal MyNumber)
    Dim Dollars, Cents, Temp
    Dim DecimalPlace, Count
    ReDim Place(9) As String
    Place(2) = "Thousand "
    Place(3) = "Million "
    Place(4) = "Billion "
    Place(5) = "Trillion "

    MyNumber = Trim(Str(MyNumber))
    DecimalPlace = InStr(MyNumber, ".")
    If DecimalPlace > 0 Then
        Cents = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & _
                  "00", 2))
        MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
    End If
    Count = 1
    Do While MyNumber <> ""
        Temp = GetHundreds(Right(MyNumber, 3))
        If Temp <> "" Then Dollars = Temp & Place(Count) & Dollars
        If Len(MyNumber) > 3 Then
            MyNumber = Left(MyNumber, Len(MyNumber) - 3)
        Else
            MyNumber = ""
        End If
        Count = Count + 1
    Loop
    Select Case Dollars
        Case ""
            Dollars = "No Dollars"
        Case "One "
            Dollars = "One Dollar"
         Case Else
            Dollars = Dollars & "Dollars"
    End Select
    Select Case Cents
        Case ""
            Cents = " and No Cents"
        Case "One "
            Cents = " and One Cent"
              Case Else
            Cents = " and " & Cents & "Cents"
    End Select
    SpellNumber = Dollars & Cents
    
End Function
---------------------------------------------------------------------------------------------------------------------------
Function GetHundreds(ByVal MyNumber)
    Dim Result As String
    If Val(MyNumber) = 0 Then Exit Function
    MyNumber = Right("000" & MyNumber, 3)
'Convert the hundreds place.
    If Mid(MyNumber, 1, 1) <> "0" Then
        Result = GetDigit(Mid(MyNumber, 1, 1)) & "Hundred "
    End If
'Convert the tens and ones place.
    If Mid(MyNumber, 2, 1) <> "0" Then
        Result = Result & GetTens(Mid(MyNumber, 2))
    Else
        Result = Result & GetDigit(Mid(MyNumber, 3))
    End If
    GetHundreds = Result
    
End Function
---------------------------------------------------------------------------------------------------------------------------
Function GetTens(TensText)
    Dim Result As String
    Result = "" ' Null out the temporary function value.
    If Val(Left(TensText, 1)) = 1 Then   ' If value between 10-19...
        Select Case Val(TensText)
            Case 10: Result = "Ten "
            Case 11: Result = "Eleven "
            Case 12: Result = "Twelve "
            Case 13: Result = "Thirteen "
            Case 14: Result = "Fourteen "
            Case 15: Result = "Fifteen "
            Case 16: Result = "Sixteen "
            Case 17: Result = "Seventeen "
            Case 18: Result = "Eighteen "
            Case 19: Result = "Nineteen "
            Case Else
        End Select
    Else ' If value between 20-99...
        Select Case Val(Left(TensText, 1))
            Case 2: Result = "Twenty "
            Case 3: Result = "Thirty "
            Case 4: Result = "Forty "
            Case 5: Result = "Fifty "
            Case 6: Result = "Sixty "
            Case 7: Result = "Seventy "
            Case 8: Result = "Eighty "
            Case 9: Result = "Ninety "
            Case Else
        End Select
        Result = Result & GetDigit _
            (Right(TensText, 1))  ' Retrieve ones place.
    End If
    GetTens = Result
    
End Function
---------------------------------------------------------------------------------------------------------------------------
Function GetDigit(Digit)
    Select Case Val(Digit)
        Case 1: GetDigit = "One "
        Case 2: GetDigit = "Two "
        Case 3: GetDigit = "Three "
        Case 4: GetDigit = "Four "
        Case 5: GetDigit = "Five "
        Case 6: GetDigit = "Six "
        Case 7: GetDigit = "Seven "
        Case 8: GetDigit = "Eight "
        Case 9: GetDigit = "Nine "
        Case Else: GetDigit = ""
    End Select
    
End Function
 
Upvote 0
Hi Mark858,
Thank you for your help and I will try to answer your questions as best as I can.

As per your first question, No, I don't think nor can I identify any of the cells that my ranges and offsets refer to in the code as activating or selecting the cells could be triggering a recalculation of the formulas.

Second question: No, the words Application.Volatile are not in the SpellNumber Function

Here is the SpellNumber Function incase you'd like to see it.

VBA Code:
Option Explicit

'Main Function
Function SpellNumber(ByVal MyNumber)
    Dim Dollars, Cents, Temp
    Dim DecimalPlace, Count
    ReDim Place(9) As String
    Place(2) = "Thousand "
    Place(3) = "Million "
    Place(4) = "Billion "
    Place(5) = "Trillion "

    MyNumber = Trim(Str(MyNumber))
    DecimalPlace = InStr(MyNumber, ".")
    If DecimalPlace > 0 Then
        Cents = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & _
                  "00", 2))
        MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
    End If
    Count = 1
    Do While MyNumber <> ""
        Temp = GetHundreds(Right(MyNumber, 3))
        If Temp <> "" Then Dollars = Temp & Place(Count) & Dollars
        If Len(MyNumber) > 3 Then
            MyNumber = Left(MyNumber, Len(MyNumber) - 3)
        Else
            MyNumber = ""
        End If
        Count = Count + 1
    Loop
    Select Case Dollars
        Case ""
            Dollars = "No Dollars"
        Case "One "
            Dollars = "One Dollar"
         Case Else
            Dollars = Dollars & "Dollars"
    End Select
    Select Case Cents
        Case ""
            Cents = " and No Cents"
        Case "One "
            Cents = " and One Cent"
              Case Else
            Cents = " and " & Cents & "Cents"
    End Select
    SpellNumber = Dollars & Cents
  
End Function
---------------------------------------------------------------------------------------------------------------------------
Function GetHundreds(ByVal MyNumber)
    Dim Result As String
    If Val(MyNumber) = 0 Then Exit Function
    MyNumber = Right("000" & MyNumber, 3)
'Convert the hundreds place.
    If Mid(MyNumber, 1, 1) <> "0" Then
        Result = GetDigit(Mid(MyNumber, 1, 1)) & "Hundred "
    End If
'Convert the tens and ones place.
    If Mid(MyNumber, 2, 1) <> "0" Then
        Result = Result & GetTens(Mid(MyNumber, 2))
    Else
        Result = Result & GetDigit(Mid(MyNumber, 3))
    End If
    GetHundreds = Result
  
End Function
---------------------------------------------------------------------------------------------------------------------------
Function GetTens(TensText)
    Dim Result As String
    Result = "" ' Null out the temporary function value.
    If Val(Left(TensText, 1)) = 1 Then   ' If value between 10-19...
        Select Case Val(TensText)
            Case 10: Result = "Ten "
            Case 11: Result = "Eleven "
            Case 12: Result = "Twelve "
            Case 13: Result = "Thirteen "
            Case 14: Result = "Fourteen "
            Case 15: Result = "Fifteen "
            Case 16: Result = "Sixteen "
            Case 17: Result = "Seventeen "
            Case 18: Result = "Eighteen "
            Case 19: Result = "Nineteen "
            Case Else
        End Select
    Else ' If value between 20-99...
        Select Case Val(Left(TensText, 1))
            Case 2: Result = "Twenty "
            Case 3: Result = "Thirty "
            Case 4: Result = "Forty "
            Case 5: Result = "Fifty "
            Case 6: Result = "Sixty "
            Case 7: Result = "Seventy "
            Case 8: Result = "Eighty "
            Case 9: Result = "Ninety "
            Case Else
        End Select
        Result = Result & GetDigit _
            (Right(TensText, 1))  ' Retrieve ones place.
    End If
    GetTens = Result
  
End Function
---------------------------------------------------------------------------------------------------------------------------
Function GetDigit(Digit)
    Select Case Val(Digit)
        Case 1: GetDigit = "One "
        Case 2: GetDigit = "Two "
        Case 3: GetDigit = "Three "
        Case 4: GetDigit = "Four "
        Case 5: GetDigit = "Five "
        Case 6: GetDigit = "Six "
        Case 7: GetDigit = "Seven "
        Case 8: GetDigit = "Eight "
        Case 9: GetDigit = "Nine "
        Case Else: GetDigit = ""
    End Select
  
End Function
Thanks for your help, but I decided to simply remove the function =SpellNumber(C28) from the sheet whenever I want to run a macro in Step Mode.
Then, after I'm done working on my VBA Macro, I enter it back into the sheet.

JohnZ1156
 
Upvote 0
Solution

Forum statistics

Threads
1,215,053
Messages
6,122,888
Members
449,097
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top