+ Reply to Thread
Results 1 to 6 of 6

Error running Match function in VBA

Hybrid View

CrystalNewb Error running Match function... 12-07-2009, 01:11 PM
DonkeyOte Re: Error running Match... 12-07-2009, 01:18 PM
Jack in the UK Re: Error running Match... 12-07-2009, 01:19 PM
CrystalNewb Re: Error running Match... 12-07-2009, 02:03 PM
DonkeyOte Re: Error running Match... 12-07-2009, 02:05 PM
CrystalNewb Re: Error running Match... 12-07-2009, 03:20 PM
  1. #1
    Registered User
    Join Date
    10-23-2009
    Location
    Sarasota, Florida
    MS-Off Ver
    Excel 2007
    Posts
    30

    Error running Match function in VBA

    Any idea why I would be getting an error saying:

    Unable to get the Match property of the worksheetfunction class?

    Here is my code

    Sub Winner()
    
    Dim FirstScore As Double
    Dim FirstPlace As String
    Dim TheMatch As Integer
    
    
    FirstScore = WorksheetFunction.Max(Range("GrandTotal"))
    TheMatch = WorksheetFunction.Match(12, GrandTotal, 0)
    FirstPlace = WorksheetFunction.Index(B1, E1, TheMatch)
    
    MsgBox "First Place is " & FirstPlace & " with " & FirstScore & " Points.", vbOKOnly, "Reading of the Scores"
    
    End Sub
    Last edited by CrystalNewb; 12-07-2009 at 03:21 PM.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Error running Match function in VBA

    You need to encase your Ranges... see FirstScore use of Range and compare that to the syntax used in TheMatch, same holds true for FirstPlace.

    Also your INDEX formula does not make much sense to me... INDEX(Range,Row_Index,Column_Index)

  3. #3
    Valued Forum Contributor
    Join Date
    07-21-2008
    Location
    London, UK
    Posts
    326

    Re: Error running Match function in VBA

    GrandTotal is not defined

  4. #4
    Registered User
    Join Date
    10-23-2009
    Location
    Sarasota, Florida
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Error running Match function in VBA

    GrandTotal is a range on my worksheet.
    I'm including an attachment this time with what I have so far.
    I'm still getting the same Error though.

    I've got a formula working on the worksheet itself but i'd really rather have a message box.

    Sub Winner()
    
    Dim FirstScore As Double
    Dim FirstPlace As String
    Dim TheMatch As Integer
    
    
    FirstScore = WorksheetFunction.Max(Range("GrandTotal"))
    TheMatch = WorksheetFunction.Match("FirstScore", "GrandTotal", 0)
    FirstPlace = WorksheetFunction.Index("B1:E1", TheMatch)
    
    MsgBox "First Place is " & FirstPlace & " with " & FirstScore & " Points.", vbOKOnly, "Reading of the Scores"
    
    End Sub
    What am I doing wrong here?
    Attached Files Attached Files

  5. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Error running Match function in VBA

    As mentioned earlier

    Range("GrandTotal")
    is a valid Range whereas

    "GrandTotal"
    is not.

  6. #6
    Registered User
    Join Date
    10-23-2009
    Location
    Sarasota, Florida
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Error running Match function in VBA

    Sorry, misunderstood you.

    Works perfectly now, Thank you very much

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1