I'm looking for some help with running a VBA lookup Function. I have setup two search functions designed to find the start and end of the data and set that as the range of the vlookup. The part I'm having trouble with appears to be setting the range correctly. I have the integer values of the rows and the columns should remain standard. The data will be between Columns B and I.
The currently shown code appears to rather than set the boundries of the code in the range area, return the value of those cells which of courser results in an error. Thanks In advance :)
Does anybody know I would go about setting the range/fixing the vlookup ? the current error: unable to get the vlookup property of the worksheet function class
PotatoePriceEuro.value and lengthinputtext.value are textbox inputs on a userform. Truecheck is a global variable from earlier on inside the module, it contains the keyword searched for in the first two search functions.
The goal of the program is to search a sheet and find the first and last occurance of a particular string as given by a textbox in the userform (the string in truecheck) and then set that as the range for the vlookup. the vlookup is then passed a numeric term from another textbox on the userform (lengthinputtext.value) which then searches column C for that number and returns the value of the cell to its left. Note that the keyword for setting the range is in Column B and the length to be search within the range will be in column C
Private Sub optionselect()
Dim LastLocation As Range
Dim FirstLocation As Range
Dim FirstRow As Long
Dim LastRow As Long
Dim SearchVal As String
Dim returnval As Integer
Set FirstLocation = Range("B:B").Find(truecheck, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows)
Set LastLocation = Range("B:B").Find(truecheck, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, searchdirection:=xlPrevious)
FirstRow = FirstLocation.Row
LastRow = LastLocation.Row
PotatoPriceEuro.Value = Application.WorksheetFunction.VLookup(LengthInputText.Value, _
Range(Cells(FirstRow, 3), Cells(LastRow, 9)), 2, False)
End Sub