+ Reply to Thread
Results 1 to 3 of 3

WorksheetFunction.Match returns error with String variable, but not with number

  1. #1
    Registered User
    Join Date
    01-29-2015
    Location
    New York, US
    MS-Off Ver
    2010 Professional Plus
    Posts
    8

    WorksheetFunction.Match returns error with String variable, but not with number

    Here is the current code that I've written so far:

    Sub Create_T_Tables()

    Application.ScreenUpdating = False
    Application.CutCopyMode = False

    Dim RowCount As Long, N_Row As Long, N_Table_Sub As Long, N_Column As Long, N_Table As Long, I_Table As Long, S_Table As Long, C As Long, C2 As Long
    Dim T_List As String, FilePath As String, S_Name As String, EP As String, Gender As String
    Dim WS As Worksheet, T_List_WS As Worksheet, S_WS As Worksheet, T_Table_WS As Worksheet
    Dim MainWB As Workbook, PasteWB As Workbook

    T_List = "Termination_Tables_List"
    Set MainWB = ActiveWorkbook

    'For Each WS In MainWB.Worksheets
    ' WS.Visible = xlSheetVisible
    'Next

    Set T_List_WS = MainWB.Sheets(T_List)
    Set T_Table_WS = MainWB.Sheets("Temp_Table")
    FilePath = MainWB.Path & "\AXIS_Import.xlsx"

    N_Row = 177
    N_Table_Sub = 4
    N_Column = 121
    RowCount = T_List_WS.Cells(Rows.Count, "A").End(xlUp).Row
    N_Table = RowCount - 1

    For I_Table = 1 To N_Table
    EP = Range("EliminationPeriod").Offset(I_Table, 0)
    Gender = Range("Gender").Offset(I_Table, 0)
    For S_Table = 1 To 5
    If EP = 3 Then
    If S_Table = 2 Then
    S_Table = 3
    End If
    Else
    If S_Table = 1 Then
    S_Table = 2
    End If
    End If
    S_Name = Range("SourceTables").Offset(I_Table, S_Table - 1)
    If S_Name <> "" Then
    For Each WS In MainWB.Sheets
    If Right(WS.Name, Len(WS.Name) - 6) = S_Name Then
    WS.Activate
    If Gender = "M" Then
    Range("A1").Select
    Range(Selection.End(xlDown), Selection.End(xlToRight)).Select
    Selection.Copy

    T_Table_WS.Activate
    Cells(4, WorksheetFunction.Match(EP, Range("2:2"), 0)).Select
    C = 1
    Do Until Selection.Offset(C, 0) = ""
    C = C + 1
    Loop
    Cells(4 + C, WorksheetFunction.Match(EP, Range("2:2"), 0)).Select
    Selection.PasteSpecial Paste:=xlPasteValues, operation:=xlNone, skipBlanks:=False, Transpose:=True

    Exit For
    End If
    End If
    Next
    End If
    Next S_Table
    Next I_Table


    More specifically this is the part which returns an error:

    Cells(4, WorksheetFunction.Match(EP, Range("2:2"), 0)).Select

    However, when I use

    Cells(4, WorksheetFunction.Match(3, Range("2:2"), 0)).Select or
    Cells(4, WorksheetFunction.Match(6, Range("2:2"), 0)).Select,

    since EP can only have 2 values, '3' or '6' it works fine. If I put EP in the function it gives me error 1004: Unable to get the match property of the Worksheet Function class.

    This is really annoying, it could be something really simple that I'm missing. But I'm developing this code further and I want to use EP instead of the exact values. Any help will be appreciated.

    Thanks,
    Last edited by IntisarN; 10-20-2015 at 03:07 PM.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: WorksheetFunction.Match returns error with String variable, but not with number

    Have you tried declaring EP as Long instead of String?

    PS Can you add code tags when posting code?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    01-29-2015
    Location
    New York, US
    MS-Off Ver
    2010 Professional Plus
    Posts
    8

    Re: WorksheetFunction.Match returns error with String variable, but not with number

    Yep EP As Long worked.

    I wasn't aware of the code tags - will do in future.

    Thank you for the quick response!

+ 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. [SOLVED] WorksheetFunction.Match giving error
    By Taemex in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-03-2015, 10:49 PM
  2. Error using Match method of WorksheetFunction
    By szepeda in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-18-2013, 08:13 PM
  3. [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
  4. Application.Worksheetfunction.match ERROR
    By Guido Meng in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-28-2013, 01:27 PM
  5. WorksheetFunction Match Error: Object Required
    By cschoyer in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-06-2012, 09:30 AM
  6. 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
  7. 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

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