0

I am just starting to learn VBA. I am using the following code but am getting an error when I try to run Sub test:

Compile Error: Variable not defined

Can you help me figure out what is wrong?

Private Sub CommandButton1_Click()
        Dim dblPrincipalAmt As Double
        Dim dblInterestRate As Double
        Dim intYears As Integer
        Dim dblInterestAmt As Double
        
        If Not IsNumeric(txtPrincipalAmt) Then
            MsgBox "INVALID PRINCIPAL AMOUNT"
            Exit Sub
        End If
        
        If Not IsNumeric(txtInterestRate) Then
            MsgBox "INVALID INTEREST RATE"
            Exit Sub
        End If
        
        If Not IsNumeric(txtYears) Then
            MsgBox "INVALID YEAR"
            Exit Sub
        End If
        
        Let dblPrincipalAmt = txtPrincipalAmt
        Let dblInterestRate = txtInterestRate
        Let intYears = txtYears
        
        Let dblInterestAmt = dblPrincipalAmt * dblInterestRate * intYears
        Let TBIA = dblInterestAmt
    
    
End Sub

I am trying to find the error so that I can fix it right away.

3
  • Side note: Let is deprecated. Commented Nov 28, 2023 at 20:59
  • The compiler is telling you. If you need more assistance then install the free and fantastic Rubberduck addin for VBA and pay attention to the code inspections. Commented Nov 28, 2023 at 23:37
  • What should I do then? It says Compile Error and then highlights the txtPrincipalAmt Commented Nov 29, 2023 at 3:39

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.