Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

VlookupWorkbook error

0

I have been using the vlookupworkbook successfully for 6 months in the same workbook looking up teh same data. a couple of weeks ago the formula just started returning #Value!.  Error checker looks like the workbook funtion is no longer recognized. The code has not changed nor the formula. Workbook has 350 sheets, any suggestions to resolve this woudl be appreciated. 

<Function VLOOKUPWORKBOOK( _

    lookup_value As Variant, _

    table_array As Range, _

    col_index_num As Integer, _

    Optional range_lookup As Boolean, _

    Optional sheets_to_exclude_1 As String, _

    Optional sheets_to_exclude_2 As String, _

    Optional sheets_to_exclude_3 As String, _

    Optional sheets_to_exclude_4 As String, _

    Optional sheets_to_exclude_5 As String _

)

'------------------------------------------------'

'------------------------------------------------'

'               TeachExcel.com

'------------------------------------------------'

'------------------------------------------------'

Dim mySheet As Worksheet

Dim value_to_return

Dim sheets_to_exclude

On Error Resume Next

'Put sheets to exclude into an array

sheets_to_exclude = Array(sheets_to_exclude_1, sheets_to_exclude_2, sheets_to_exclude_3, sheets_to_exclude_4, sheets_to_exclude_5)

'Cycle through all sheets in the workbook

For Each mySheet In ActiveWorkbook.Worksheets

    'Check if the sheet needs to be excluded or not.

    If Not (UBound(Filter(sheets_to_exclude, mySheet.Name)) > -1) Then

        With mySheet

            Set table_array = .Range(table_array.Address)

            'Run the actual vlookup function on the current sheet that is being looped though.

            value_to_return = WorksheetFunction.VLookup(lookup_value, table_array, col_index_num, range_lookup)

        End With

        'Exit the loop once have a value to return.

        If Not IsEmpty(value_to_return) Then

            Exit For

        End If

    End If

Next mySheet

'Send the result back to the cell that contains the function.

VLOOKUPWORKBOOK = value_to_return

End Function>

here is the formula I use:

=IF(VLOOKUPWORKBOOK(V321,B:B,1,FALSE,"Order Check","Issues Log")=V321,"Yes","NO")

result now:

  #VALUE!
Answer
Discuss

Discussion

Methos

Your nested IF formula (to check for V321 contents in parts of the workbook) does work from me UNLESS cell V321 actually contains an error ( #N/A , #DIV0 etc.) when it reports that error.

In your discussion (under Willie's Answer) ou say the problem "in the formula seems to be with the private funtion  vlookupworkbook" but to test that Excel still "sees" the function, put this in another cell:
=VLOOKUPWORKBOOK(V321,B:B,1,FALSE,"Order Check","Issues Log")

(note how I selected the formula text then used the CODE button to present the formula as above).

What happens? (If found, it should return whatever's in V321, 0 if not.)
If the #VALUE error is returned, what's the value or formula in V321?  Can you attach a file with just a few sheets (not all 350!), being sure not to include personal; data?

John_Ru
John_Ru (rep: 6377) Aug 29, '24 at 9:08 am
Forgot to say- to attach a file, edit your original question and use the Add Files... button to upload a representative Excel file (without any personal data) to show some of your existing data (and macros). Then we should be able to give specific help.
John_Ru (rep: 6377) Aug 29, '24 at 9:12 am
Add to Discussion

Answers

0

Hello methos and welcome to the forum,

The #VALUE! Error can be tricky to locate. This error can be caused for a few different reasons. Some of the most common are: a blank cell containing a space, numbers entered as text, special characters. Also, your formula, as written, looks like it creates a circular reference : does V321 = V321.

One way to check for a formula error is to: select the cell with your formula, then click the "Formulas" tab and click on "Evaluate Formula". Click the "Evaluate" button – an underscore will indicate which part of the formula is being evaluated. Continue clicking "Evaluate" to progress through the formula and it should indicate where the problem lies.

In the following link look at "Locate the source of the error".

#VALUE! ERROR

If this solves things for you please mark mt answer as Selected.

Cheers   :-)

Discuss

Discussion

V321 does = v321 in the formula because the vlookup worbook is nexted inside an if formula.The result from the VlookupWorkbook is checking to see if the value exists in the workbook, If it does the vlue is Yes and if not the value is no. The problme in the formula seems to be with the private funtion  vlookupworkbook but as I stated to begin with the code has not been changed or modified, excel just suddenly stopped recognizing it as being valid. 
methos Aug 28, '24 at 2:16 pm
Obviously something in the workbook - other than the formula - has changed. Does data on any worksheet change? Is any data imported from another workbook or website? Maybe the path to the workbook or website has changed. Have you tried using "Evaluate Formula" to have Excel try to locate the problem?
WillieD24 (rep: 587) Aug 28, '24 at 3:09 pm
Date is not imported I enter everythign manually and all cells are the same format, first thing i checked, and all cells have correct information in them. 

I have used evaluate formula and teh result shows vlookupworkbook as the error.  It looks to me like something changed from an update to excel or somethign else that makes it think this funtion is no longer valid. The workbook has been in the same spot for a couple of years. I added the vlookupworkbook after finding it posted on you tube from this website, As I said it has worked great for 6 months. below is the result of the "Evaluate formula". I had our IT group look into this and they said none of the updates should have impacted my code. SO I am at a loss as to what teh problem is. 

methos Aug 29, '24 at 10:40 am
Methos, I don't have Excel 2016 but VLOOKUP still works in 365 (and so the VBA function does too, as I said in my Discussion point under your question- did you see that?).

BTW you said "below is the result of the "Evaluate formula"and I suspect you pasted an image- but that doesn't work in the Forum (look back at your post), sorry. Better that you explain verbally.

John_Ru
John_Ru (rep: 6377) Aug 29, '24 at 11:02 am
@methos
Let’s start by looking at the facts as you have presented them. 1) the formula has not changed; 2) the formula looks for the value in V321 in column “B”; 3) no data / values are from external sources; 4) all data is entered manually; all cells are the same format; 5) Excel’s “Evaluate Formula” utility shows the VLOOKUPWORKBOOK function to be the problem.
If the function is the problem that indicates there is a problem (error) with a piece of data it is trying to use. This can happen if there is a space before or after the number. For example: if you enter 1234 with a space before it, Excel reads this as 5 characters (text) and not a 4-digit number. The same would happen if a space was typed at the end of the digits. It is easy to miss a space when doing a visual check, especially if the space is after the digits (it’s happened to me).
I have tried your formula (Excel 2016) and got no errors. I can only conclude that one of the data points in column “B” is incorrect in some way. It might even be the entry in V321.
One other item to check is the VBA code for the function – maybe it got corrupted somehow.
I’ve seen it before where manual data entry has been the root cause.
All this is a long explanation of my original answer.
Aug. 30/24 - also check that there are no spaces in the middle of a number (ex: 123 456, 12 34 56)
Cheers   :-)
WillieD24 (rep: 587) Aug 29, '24 at 7:18 pm
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login