LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default vba range in vlookup

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

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
vlookup range Randy Excel Discussion (Misc queries) 4 May 14th 10 03:59 PM
Range Vlookup deen Excel Worksheet Functions 1 April 21st 10 12:32 PM
Using VLOOKUP with a 3D range Cassie Excel Worksheet Functions 4 September 11th 07 11:29 PM
vlookup range changes Hobbes2006 Excel Worksheet Functions 3 April 18th 06 07:07 PM
Vlookup - Range Mark Excel Discussion (Misc queries) 1 April 15th 05 05:52 PM


All times are GMT +1. The time now is 08:47 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"