+ Reply to Thread
Results 1 to 9 of 9

Using INDEX and MATCH in vba.

  1. #1
    Registered User
    Join Date
    09-16-2010
    Location
    Glasgow
    MS-Off Ver
    2010
    Posts
    68

    Using INDEX and MATCH in vba.

    Hi Folks,

    I am having issues implementing the use of INDEX and MATCH in a macro, basically I would need a macro that loop through all cells of a column applying a INDEX and MATCH formula to it only if a value is found (i.e. if the formula does not return #N/A), otherwise do nothing. So far I wrote the following:

    Please Login or Register  to view this content.
    However I am having issues with the above line in bold (I tried to write a statement to apply the INDEX & MATCH formula if its result is not #N/A), the macro stops at that line with Run-time errror 1004.

    The formula in itself is:

    Please Login or Register  to view this content.
    Could anyone point me to the right direction in order to convert such a formula into vba?
    I googled most of the evening and could not find the right syntax.

    Thanks a lot,
    Ant

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: Using INDEX and MATCH in vba.

    Did you try just Evaluate

    Please Login or Register  to view this content.

  3. #3
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Using INDEX and MATCH in vba.

    You may test match result with Iserror:
    Please Login or Register  to view this content.
    Last edited by Izandol; 12-12-2013 at 08:16 AM. Reason: spelling

  4. #4
    Registered User
    Join Date
    09-16-2010
    Location
    Glasgow
    MS-Off Ver
    2010
    Posts
    68

    Re: Using INDEX and MATCH in vba.

    Hi zbor, Izandol,

    Thanks a lot to both of you, both codes work great. To summarise, I can either use:

    Please Login or Register  to view this content.
    or

    Please Login or Register  to view this content.
    The remaining question, what is the most efficient code? Is there any difference between both of them?

    PS: Why cannot I set i to be an Integer? After all the row # is always going to be a number?

  5. #5
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Using INDEX and MATCH in vba.

    Integer may only hold numbers up to 32767. Worksheet has many more rows than this.

  6. #6
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Using INDEX and MATCH in vba.

    Just to add, that naming a variable 'index', the same as a worksheet function name, is a recipe for confusion...
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  7. #7
    Registered User
    Join Date
    09-16-2010
    Location
    Glasgow
    MS-Off Ver
    2010
    Posts
    68

    Re: Using INDEX and MATCH in vba.

    Integer may only hold numbers up to 32767
    Thanks Izandol, I was not aware of this.

    aming a variable 'index', the same as a worksheet function name, is a recipe for confusion...
    You are very right and just realised it is where I messed up in my original code, apologies for this.

    I have now 3 different alternatives to use INDEX & MATCH in vba:

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Are there any advantages of using one over the other?

  8. #8
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Using INDEX and MATCH in vba.

    Last one is more efficient. Second one may be written to be more efficient:
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    09-16-2010
    Location
    Glasgow
    MS-Off Ver
    2010
    Posts
    68

    Re: Using INDEX and MATCH in vba.

    Thanks a lot Izandol, I will go with your suggestion.

+ 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: 6
    Last Post: 11-08-2013, 10:29 PM
  2. Index match offset to get subsequent index values in a column
    By Andrew_Step in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-06-2013, 02:55 PM
  3. Replies: 3
    Last Post: 05-02-2013, 01:31 AM
  4. [SOLVED] VBA for creating Index-Match every 2 rows where INDEX refer to a different column per row
    By bisaya789 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-22-2012, 03:46 AM
  5. Replies: 5
    Last Post: 02-29-2012, 08:51 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