Excel VBA issue - XLookup #Value error

Joe Joel 25 Reputation points
2023-03-07T11:32:48.5833333+00:00

I'm having issues with a VBA function and can't understand why. I've tracked the error to a specific point as shown below. When I run this funciton using this code, it works exactly as expected.

User's image

User's image

However, When I run this code, which should do exactly the same thing, It gives me a #VALUE! error as shown below.

User's image

User's image

Could somebody please advise how to fix this? The rest of the function runs as intended and will work once this returs the correct value and not an error.

Thanks

Microsoft 365 and Office | Development | Other
Microsoft 365 and Office | Excel | For business | Windows
{count} votes

Answer accepted by question author
  1. Viorel 125.6K Reputation points
    2023-03-08T01:13:33.2566667+00:00

    Maybe you should use a range:

    Dim arg3 as Range
    Set arg3 = Range("D9")
    

    Or maybe

    Dim arg3
    arg3 = Range("D9").Value2
    
    2 people found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.