+ Reply to Thread
Results 1 to 8 of 8

INDEX MATCH to return the row number?

Hybrid View

  1. #1
    Registered User
    Join Date
    10-08-2012
    Location
    Cedar Falls, Iowa
    MS-Off Ver
    Excel 2007
    Posts
    50

    INDEX MATCH to return the row number?

    I am doing a multiple criteria search using INDEX MATCH. The code works well to produce a formula, but what I really need it to do is return the row number when it finds the multiple match.

    Sub new_forecast()
        Set fSheet = Workbooks("TEST 2.xlsx").Worksheets("Product Split Filter")
        Set nSheet = Workbooks("TEST.xlsm").Worksheets("2021 Forecast")
        
        fSheet.Activate
        fLastRow = ActiveSheet.Cells(65000, 1).End(xlUp).row
        
        Rows("1:1").Select
        With Selection
            .Find(What:="fModel").Activate
            fModCol = ActiveCell.Column
            .Find(What:="Factory").Activate
            fFacCol = ActiveCell.Column
            .Find(What:="Sub_Region").Activate
            fRegCol = ActiveCell.Column
            .Find(What:="Units").Activate
            fUnitCol = ActiveCell.Column
        End With
        
        nSheet.Activate
        nLastRow = ActiveSheet.Cells(65000, 1).End(xlUp).row
        
        Rows("1:1").Select
        With Selection
            .Find(What:="fModel").Activate
            nModCol = ActiveCell.Column
            .Find(What:="Factory").Activate
            nFacCol = ActiveCell.Column
            .Find(What:="Sub_Region").Activate
            nRegCol = ActiveCell.Column
        End With
        
        fSheet.Activate
        
        For fCast = 2 To fLastRow
            fModel = fSheet.Cells(fCast, fModCol).Value
            fFactory = fSheet.Cells(fCast, fFacCol).Value
            fRegion = fSheet.Cells(fCast, fRegCol).Value
            fUnits = fSheet.Cells(fCast, fUnitCol).Value
                nSheet.Activate
                 Range(Cells(14 + fCast, 1), Cells(14 + fCast, 1)).FormulaArray = "=INDEX(T2:T10, MATCH(" & Chr(34) & fModel & fFactory & fRegion & Chr(34) & ", M2:M10 & N2:N10 & R2:R10, 0))"     ' I really need this to just return the row number
        
    Next fCast
        
    End Sub
    Last edited by cabroncito29; 09-30-2015 at 02:24 PM.

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,960

    Re: INDEX MATCH to return the row number?

    post deleted
    Last edited by protonLeah; 09-30-2015 at 02:35 PM.
    Ben Van Johnson

  3. #3
    Registered User
    Join Date
    10-08-2012
    Location
    Cedar Falls, Iowa
    MS-Off Ver
    Excel 2007
    Posts
    50

    Re: INDEX MATCH to return the row number?

    Sorry about that!

  4. #4
    Registered User
    Join Date
    10-08-2012
    Location
    Cedar Falls, Iowa
    MS-Off Ver
    Excel 2007
    Posts
    50

    INDEX MATCH - can it return the row number?

    So I love the idea of INDEX MATCH for a multiple criteria search. I have 2 separate worksheets and pull 3 pieces of data from one and search for the appropriate match on the other. I have figured out how to return a value, but can I have the code return the row number?

    Sub new_forecast()
        Set fSheet = Workbooks("example2.xlsm").Worksheets("Sheet1")
        Set nSheet = Workbooks("example1.xlsm").Worksheets("Sheet1")
        
        fSheet.Activate
        fLastRow = ActiveSheet.Cells(65000, 1).End(xlUp).Row
        
        Rows("1:1").Select
        With Selection
            .Find(What:="Name").Activate
            fName = ActiveCell.Column
            .Find(What:="Age").Activate
            fAge = ActiveCell.Column
            .Find(What:="Gender").Activate
            fGender = ActiveCell.Column
        End With
        
        nSheet.Activate
        nLastRow = ActiveSheet.Cells(65000, 1).End(xlUp).Row
        
        Rows("1:1").Select
        With Selection
            .Find(What:="Name").Activate
            nName = ActiveCell.Column
            .Find(What:="Age").Activate
            nAge = ActiveCell.Column
            .Find(What:="Gender").Activate
            nGender = ActiveCell.Column
        End With
        
        fSheet.Activate
        
        For fCast = 2 To fLastRow
            firstName = fSheet.Cells(fCast, fName).Value
            firstAge = fSheet.Cells(fCast, fAge).Value
            firstGender = fSheet.Cells(fCast, fGender).Value
                nSheet.Activate
                    Range(Cells(14 + fCast, 1), Cells(14 + fCast, 1)).FormulaArray = "=INDEX(D2:D6, MATCH(" & Chr(34) & _
                    firstName & firstAge & firstGender & Chr(34) & ", A2:A6 & B2:B6 & C2:C6, 0))"
        Next fCast
        
    End Sub
    Attached Files Attached Files

  5. #5
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: INDEX MATCH - can it return the row number?

    Remove the INDEX function in your formula and add +1 to the MATCH result because your search range starts at row 2

    Range(Cells(14 + fCast, 1), Cells(14 + fCast, 1)).FormulaArray = "=MATCH(" & Chr(34) & _
                    firstName & firstAge & firstGender & Chr(34) & ", A2:A6 & B2:B6 & C2:C6, 0)+1"
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  6. #6
    Registered User
    Join Date
    10-08-2012
    Location
    Cedar Falls, Iowa
    MS-Off Ver
    Excel 2007
    Posts
    50

    Re: INDEX MATCH - can it return the row number?

    Works awesome! Thank you so much!!

  7. #7
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,960

    Re: INDEX MATCH to return the row number?

    Why are you INDEXing on T2:T10? Seems, all you need is the MATCH alone. It will return the smallest (first) row number in the three columns.

    Range(Cells(14 + fCast, 1), Cells(14 + fCast, 1)).FormulaArray = "=MATCH(" & Chr(34) & fModel & fFactory & fRegion & Chr(34) & ", M2:M10 & N2:N10 & R2:R10, 0)"

  8. #8
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: INDEX MATCH to return the row number?

    cabroncito29 , please do not post duplicate threads. I will combine this 1 with your other 1 because they both have comments (normally I would close 1 of them)
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

+ 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: 5
    Last Post: 10-16-2016, 02:33 AM
  2. [SOLVED] Vlookup/index/match to return all values that match
    By Asil01 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 10-09-2014, 12:49 PM
  3. [SOLVED] Combining 3 Formulas: Return all Names that Match Criteria Using Index/Match
    By bchilme in forum Excel Formulas & Functions
    Replies: 20
    Last Post: 09-29-2014, 09:28 AM
  4. Using Index/Match to return multiple values for one match
    By superboy in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-10-2014, 06:21 PM
  5. VLOOKUP/INDEX/MATCH to return all values that match
    By lijia00 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-05-2014, 11:56 AM
  6. [SOLVED] Lookup/Index/Match to Return Value of Higher number rather than lower# when inbetween
    By ReedDOT in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-16-2013, 11:56 PM
  7. Replies: 3
    Last Post: 05-08-2013, 02:10 PM

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