+ Reply to Thread
Results 1 to 8 of 8

Dynamic US Map was working fine, but now I'm getting WorksheetFunction.Match 1004 errors

Hybrid View

  1. #1
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,813

    Re: Dynamic US Map was working fine, but now I'm getting WorksheetFunction.Match 1004 erro

    OK, done that, got the crash.

            With Worksheets("MainMap")
                For intState = 1 To rngStates.Rows.Count
                    strStateName = rngStates.Cells(intState, 1).Text
                    intStateValue = rngStates.Cells(intState, 2).Value
                        intColorLookup = Application.WorksheetFunction.Match(intStateValue, Range("STATE_COLORS_VISITS"), True)
                        With .Shapes(strStateName)
                            .Fill.Solid
                            .Fill.ForeColor.RGB = rngColors.Cells(intColorLookup, 1).Offset(0, 1).Interior.Color
                        End With
                Next
            End With
    intState = 22
    strStateName = MICHIGAN
    intStateValue = 55

    ?rngstates.Address
    $A$2:$B$51

    rngStates.Rows.Count = 50


    I'm guessing the problem is here:

    Sub ChangeColor()
    
    Dim LastRow As Long
    Dim FullRange As Variant
    Dim cell As Variant
    
    With ActiveSheet
        LastRow = Range("E" & Rows.Count).End(xlUp).Row
    End With
    
    Set FullRange = Range("E2:E" & LastRow)
    For Each cell In FullRange

    There's nothing in column E so that range becomes E1:E2 as Lastrow will be 1.

    Have you tidies up the worksheet and not changed the code to match?


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  2. #2
    Registered User
    Join Date
    01-22-2014
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Dynamic US Map was working fine, but now I'm getting WorksheetFunction.Match 1004 erro

    Update: SOLVED

    Turns out that if you use an approximate match in the MATCH function ("true"/"1"), the reference array needs to be in ascending/descending order. I was able to update my code to exact match and it works perfectly:

    intColorLookup = Application.WorksheetFunction.Match(intStateValue, Range("STATE_COLORS_VISITS"), 0)
    Thanks again for looking into this!
    -Chris

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 2
    Last Post: 05-24-2013, 09:32 AM
  2. [SOLVED] WorksheetFunction.match run time error '1004' with numbers but not text
    By Hussar13 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-13-2013, 05:31 PM
  3. Run-time error 1004: Unable to get the Match property of the WorksheetFunction class
    By maffmommie in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-13-2010, 09:32 AM
  4. worksheetfunction.match giving run time error '1004'
    By devo2511 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-15-2010, 04:47 PM
  5. run-time error '1004 Unable to get Match property of WorksheetFunction class
    By exl044 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-08-2010, 02:23 AM

Tags for this Thread

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