Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6094537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:41:25+00:00 2026-05-23T12:41:25+00:00

I have a problem with calling the Match function from a VBA code: it

  • 0

I have a problem with calling the Match function from a VBA code: it returns the wrong values.
I have a speadsheet like this (it’s an example):

        a               b       c                   d
1   testRange               testValue   
2   01/01/2011 00:00        03/01/2011 00:00    testValue = A4
3   02/01/2011 00:00            
4   03/01/2011 00:00        result from match function  
5   04/01/2011 00:00        3                   testResult = MATCH(C2,A2:A20,1)
6   05/01/2011 00:00            
7   06/01/2011 00:00        testResult  
8   07/01/2011 00:00        9   
9   08/01/2011 00:00            
10  09/01/2011 00:00            
11  10/01/2011 00:00            
12  11/01/2011 00:00            
13  12/01/2011 00:00            
14  13/01/2011 00:00            
15  14/01/2011 00:00            
16  15/01/2011 00:00            
17  16/01/2011 00:00            
18  17/01/2011 00:00            
19  18/01/2011 00:00            
20  19/01/2011 00:00            

the range that I’m searching is in A1:A20, and I’m looking for the value wrote in C2, that as you can see is just a value of the range (this to be sure that the value is in the range). I expect the Match function to return the number 3, like it does when called from the spreadsheet (cell C5), but the function called in VBA returns the value 9 (cell C10). I used this code:

Sub testMatch()
    testRange = Range("A2:A20")
    testValue = Range("C2")
    testResult = Application.WorksheetFunction.Match(testValue, testRange, 1)
    Range("C8") = testResult
End Sub

I have already tried to cast testValue as Date and as Double (solutions suggested in other forums), but with Date I have the same result and with Double I get the Error 1004 “Unable to get the Match property of the WorksheetFunctions class”

Any suggestion?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:41:26+00:00Added an answer on May 23, 2026 at 12:41 pm

    As suggested in other forums, you should type your variables (Date…) and use Option Explicit.

    In this case, the error comes from the use of dates inside the match function, try this :

    Application.WorksheetFunction.Match(CLng(testValue), testRange, 0)
    

    (edit > source: thanks to this thread)

    I’ve tested on your example and it works for me.

    Regards,

    Max

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have got a problem with calling a global function, which takes a pointer
I have a problem. I am coding using VS2008. I am calling webservices from
I have a problem calling a batch file from another batch file when trying
I have this problem with signal() : This code compiles fine: #include <stdio.h> #include
i have a problem calling multiple instance of a class that i have coded
I have a problem in calling a template class I have. I declared a
Here's my problem: I have an unmanaged dll that I made.I'm calling one of
Are there any inherent problems with calling an ole object from tsql? I have
Hi I have a problem handling exceptions in wcf. I have a service like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.