I
isauror
Hello,
I am building a user form and trying to get a value by using Vlookup.
However, I get an error in vba once it gets to the Select Case portion
of the module. This SELECT CASE is trying to get the range for my
vlookup formula.
How it works is depending on what ComboBox value is in the cboPrgType
will depend on what named range it will look at in the formula; all
the named ranges are in the spread sheet. I used the Select Case vba
formula to determine what range it will use. TableRange is the varible
used in the vba Vlookup formula that will determin the named range.
Here is my code:
Private Sub CommandButton1_Click()
Dim LTV As Double
Dim CLTV As Double
Dim TableRange As Range
Dim ColumnNum As Integer
Dim CurrRate As String
Dim Price As Long
If txtLoanAmtOne = vbNullString Then
MsgBox "Please enter a loan amount"
Exit Sub
End If
If txtSalesValue = vbNullString Then
MsgBox "Please enter a Sales/Appraised value"
Exit Sub
End If
LTV = CDbl(txtLoanAmtOne.Text) / CDbl(txtSalesValue.Text)
If txtLoanAmtTwo = vbNullString Then
CLTV = LTV
Else
CLTV = (CDbl(txtLoanAmtOne.Text) + CDbl(txtLoanAmtTwo.Text)) /
CDbl(txtSalesValue.Text)
End If
If LTV > 0.97 Then
MsgBox "Sorry, LTV is greater than allowable"
Exit Sub
End If
If CLTV > 1 Then
MsgBox "Sorry, CLTV is above Max CLTV"
Exit Sub
End If
txtLtvValue.Text = CDbl(LTV) * 100
txtCltvValue.Text = CDbl(CLTV) * 100
CurrRate = cboRate.Value
Select Case cboPrgType.Value
Case "MM30YFRates"
TableRange = MM30YFTable
Case "MM20YFRates"
TableRange = MM20YFTable
Case "MM15YFRates"
TableRange = MM15YFTable
Case "MM26LRates"
TableRange = MM26LTable
Case "MM36LRates"
TableRange = MM36LTable
Case "MM56LRates"
TableRange = MM56LTable
Case "MMS30YFRates"
TableRange = MMS30YFTable
Case "MMS15YFRates"
TableRange = MMS15YFTable
Case "MMS20YFRates"
TableRange = MMS20YFTable
Case "MMS3015YBRates"
TableRange = MMS3015YBTable
End Select
Select Case cboAmort.Value
Case "21"
ColumnNum = 4
Case "36"
ColumnNum = 5
Case "45"
ColumnNum = 6
End Select
Price = Application.VLookup(CurrRate, Range(TableRange), ColumnNum,
False)
txtBuyPrice.Text = CDbl(Price)
End Sub
Is my SELECT CASE set up correctly? Please help
I am building a user form and trying to get a value by using Vlookup.
However, I get an error in vba once it gets to the Select Case portion
of the module. This SELECT CASE is trying to get the range for my
vlookup formula.
How it works is depending on what ComboBox value is in the cboPrgType
will depend on what named range it will look at in the formula; all
the named ranges are in the spread sheet. I used the Select Case vba
formula to determine what range it will use. TableRange is the varible
used in the vba Vlookup formula that will determin the named range.
Here is my code:
Private Sub CommandButton1_Click()
Dim LTV As Double
Dim CLTV As Double
Dim TableRange As Range
Dim ColumnNum As Integer
Dim CurrRate As String
Dim Price As Long
If txtLoanAmtOne = vbNullString Then
MsgBox "Please enter a loan amount"
Exit Sub
End If
If txtSalesValue = vbNullString Then
MsgBox "Please enter a Sales/Appraised value"
Exit Sub
End If
LTV = CDbl(txtLoanAmtOne.Text) / CDbl(txtSalesValue.Text)
If txtLoanAmtTwo = vbNullString Then
CLTV = LTV
Else
CLTV = (CDbl(txtLoanAmtOne.Text) + CDbl(txtLoanAmtTwo.Text)) /
CDbl(txtSalesValue.Text)
End If
If LTV > 0.97 Then
MsgBox "Sorry, LTV is greater than allowable"
Exit Sub
End If
If CLTV > 1 Then
MsgBox "Sorry, CLTV is above Max CLTV"
Exit Sub
End If
txtLtvValue.Text = CDbl(LTV) * 100
txtCltvValue.Text = CDbl(CLTV) * 100
CurrRate = cboRate.Value
Select Case cboPrgType.Value
Case "MM30YFRates"
TableRange = MM30YFTable
Case "MM20YFRates"
TableRange = MM20YFTable
Case "MM15YFRates"
TableRange = MM15YFTable
Case "MM26LRates"
TableRange = MM26LTable
Case "MM36LRates"
TableRange = MM36LTable
Case "MM56LRates"
TableRange = MM56LTable
Case "MMS30YFRates"
TableRange = MMS30YFTable
Case "MMS15YFRates"
TableRange = MMS15YFTable
Case "MMS20YFRates"
TableRange = MMS20YFTable
Case "MMS3015YBRates"
TableRange = MMS3015YBTable
End Select
Select Case cboAmort.Value
Case "21"
ColumnNum = 4
Case "36"
ColumnNum = 5
Case "45"
ColumnNum = 6
End Select
Price = Application.VLookup(CurrRate, Range(TableRange), ColumnNum,
False)
txtBuyPrice.Text = CDbl(Price)
End Sub
Is my SELECT CASE set up correctly? Please help