• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 319
  • Last Modified:

Function Vlookup not working

Hi Guys, because of the Vlookup limit of 256 characters, I have had to create a Function which creates my own Vlookup, but its not working in Range ("S5") and thus getting a VALUE#.  Code is below.



Function MyVlookup(Lval As Range, c As Range, oset As Long) As Variant
Dim cl As Range
For Each cl In c.Columns(1).Cells
    If UCase(Lval) = UCase(cl) Then
        MyVlookup = cl.Offset(, oset - 1)
        Exit Function
    End If
    Next
End Function
DummyRec5.xlsx
0
Justincut
Asked:
Justincut
  • 3
1 Solution
 
andrewssd3Commented:
The immediate issue is that you have kept the fourth parameter to VLOOKUP in your function call, and have not defined it in your function. So either change your function to
Function MyVlookup(Lval As Range, c As Range, oset As Long, approx As Boolean) As Variant

Open in new window

or remove the final ',FALSE' from your function call.
0
 
andrewssd3Commented:
It's also worth noting that the sheet is very slow to calculate - this seems largely to be because you have lots of VLOOKUPs to the 'Mapping' range which is in an external workbook, and for currencies, also external.  You will speed thing up a lot if you bring this static data inline to this workbook - external VLOOKUPs are nearly always a performance nightmare. If you want to keep the independence of the external data, you can always copy and paste link the data into this workbook.  That way it will update when the external data changes, but you VLOOKUPs will be local.
0
 
JustincutAuthor Commented:
Ok, it works. This is a Excel Rec I roll every day and date and do a Vlookup on the Previous day's spreadsheet. For the Vlookup, to work, do I have to  install the Function on the Previous days spreadsheet too?
0
 
andrewssd3Commented:
No you only need it on the sheet that is doing the vlookup, unless the data you are looking up is dependent on a similar loookup in yesterday's sheet, etc...

Once you have the function in a workbook, it will be copied with it if you do your roll-over by taking a copy of today's sheet.  Note that you will need to save in a macro-enabled format (eg .xlsm) to get the macro to persist.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now