Excel 2000/97 VBA: Using the Match from the WorksheetFunction class

Posted on 2004-11-05
Last Modified: 2008-02-26
Excel 2000 (although would like to know if 97 is any different), VBA 6

On the worksheet, it is easy


Where measure is a named Range.

I thought I could do something like this in a VBA Sub/function:-

Debug.Print CStr(WorksheetFunction.Match(Q3, ActiveWorkbook.Names("Measure").RefersToRange.Areas(1).Address, 0))
(WRONG - Get "Unable to find match property in WorksheetFunction class")

Object browser says Match is in the WorksheetFunction class.

Set WF = CreateObject("Excel.WorksheetFunction")
Set WF = New Excel.WorksheetFunction not seem to create the object.

Is it possible to call the functions in the WorksheetFunction class???  Others must have needed to do this before now, how did you solve it? Go to a empty cell and change the formula on the fly - messy but a possibility??

Question by:GJPerkins
    LVL 50

    Expert Comment

    by:Dave Brett
    Hi GJPerkins,

    try something like

    MsgBox Application.WorksheetFunction.Match(Range("Q3"), Range("Measure"), 0)


    LVL 50

    Accepted Solution

    or a bit tidier with error handler for the no match case

    Dim MatchPos As Long
        On Error Resume Next
        MatchPos = Application.WorksheetFunction.Match(Range("Q3"), Range("Measure"), 0)
        If Err.Number <> 0 Then
            MsgBox "No match"
            MsgBox "Match in position " & MatchPos
        End If
        On Error GoTo 0



    Author Comment

    Cheers Dave - I feel a bit of a plonker for not twigging that!!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
    Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now