+ Reply to Thread
Results 1 to 14 of 14

VBA that does what an Index & Match does

  1. #1
    Forum Contributor
    Join Date
    02-23-2014
    Location
    Melbourne
    MS-Off Ver
    Microsoft 365
    Posts
    174

    VBA that does what an Index & Match does

    Hi Experts
    I have an excel file where I have one column where I have an Index and Match formula to populate the description from another work sheet

    It works perfectly, but because multiple people use it, the formula keeps getting deleted and file saved

    I have tried Format Change and Lock and then Protected the worksheet, but then I have other issues where rows can't be added or people like to go to the last row and just type and it adds to the table, but once protected they can't do all that

    So I was wondering if the Index and Match can be written as a VBA so when the Product Code is entered in Column F, the VBA will do the Index and Match and populate Column G with the description

    The below is the Index and Match formula that I am using

    Please Login or Register  to view this content.
    I have also attached a sample excel file

    Regards
    Rah
    Attached Files Attached Files

  2. #2
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    8,015

    Re: VBA that does what an Index & Match does

    Paste the below into the Shedule worksheet module and it will do the same as your INDEX/MATCH formula but will leave a hardcoded value in the cell rather than the result of a formula.
    Please Login or Register  to view this content.
    This version will not throw up an error the value entered is not found on the Database sheet, and will clear the cell if it already holds a value.
    Please Login or Register  to view this content.
    BSB

  3. #3
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: VBA that does what an Index & Match does

    Try this code in the worksheet module:

    Please Login or Register  to view this content.
    WBD
    Office 365 on Windows 11, looking for rep!

  4. #4
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2503
    Posts
    1,485

    Re: VBA that does what an Index & Match does

    I had created the below, I had restricted it to work only within the Product Code column of the ADatabase table. Code goes into the 'Shedule' tab code window:
    Please Login or Register  to view this content.
    I have assumed that this will be the only worksheet event on this sheet
    If things don't change they stay the same

  5. #5
    Forum Contributor
    Join Date
    02-23-2014
    Location
    Melbourne
    MS-Off Ver
    Microsoft 365
    Posts
    174

    Re: VBA that does what an Index & Match does

    Thanks BSB
    It worked

    Much Appreciated

    Rah

  6. #6
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,710

    Re: VBA that does what an Index & Match does

    Pl see file with Worksheet event.
    Code:
    Please Login or Register  to view this content.
    How to use the code
    Right click on Sheet tab --> view code
    Visual Basic (VB) window opens.
    Paste the code
    Close the VB window.
    Save the file as .xlsm
    Attached Files Attached Files
    Pl note
    Array formula should be confirmed with Ctrl+Shift+Enter keys together.
    If answere is satisfactory press * to add reputation.

  7. #7
    Forum Contributor
    Join Date
    02-23-2014
    Location
    Melbourne
    MS-Off Ver
    Microsoft 365
    Posts
    174

    Re: VBA that does what an Index & Match does

    Hi CheeseSand
    No it's not the only worksheet event, I had another, but had to remove it

    Please Login or Register  to view this content.

  8. #8
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2503
    Posts
    1,485

    Re: VBA that does what an Index & Match does

    You can include what that event was doing in the code you have chosen; I am sure @BSB will elaborate.

  9. #9
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: VBA that does what an Index & Match does

    You could combine these together. Your original code is just making the product codes upper case:

    Please Login or Register  to view this content.
    Note that the above caters for multiple product codes being pasted into the column. Not sure if that's required/relevant.

    WBD

  10. #10
    Forum Contributor
    Join Date
    02-23-2014
    Location
    Melbourne
    MS-Off Ver
    Microsoft 365
    Posts
    174

    Re: VBA that does what an Index & Match does

    Hi WDB
    Thanks for that, entering multiple codes wasn't a requirement, but a nice to have

    How would the codes need to be separated for it to work?

    Ragards
    Rah

  11. #11
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: VBA that does what an Index & Match does

    OK. If you want to go back to CheeseSandwich's solution and add in the upper case then:

    Please Login or Register  to view this content.
    WBD

  12. #12
    Forum Contributor
    Join Date
    02-23-2014
    Location
    Melbourne
    MS-Off Ver
    Microsoft 365
    Posts
    174

    Re: VBA that does what an Index & Match does

    [QUOTE

    Note that the above caters for multiple product codes being pasted into the column. Not sure if that's required/relevant.

    WBD[/QUOTE]

    This is awesome to have... Question: How would multiple product codes will be entered for it to work? Do the product codes need a seperator?

  13. #13
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2503
    Posts
    1,485

    Re: VBA that does what an Index & Match does

    Quote Originally Posted by rahul_ferns76 View Post
    Question: How would multiple product codes will be entered for it to work? Do the product codes need a seperator?
    I think if they are pasted one under another - if you paste a block of data the it will look up for the pasted block. It is not multiple product codes in the same cell.

    That was in the WBD version of the code
    Last edited by CheeseSandwich; 07-22-2022 at 04:27 AM.

  14. #14
    Forum Contributor
    Join Date
    02-23-2014
    Location
    Melbourne
    MS-Off Ver
    Microsoft 365
    Posts
    174

    Re: VBA that does what an Index & Match does

    Thanks CS. Much Appreciated

+ 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] index match function vs index match vba type mismatch
    By johnstylez in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-14-2022, 03:29 PM
  2. [SOLVED] INDEX+MATCH instead of VLOOKUP+MATCH, why is INDEX a better choice and how to re-write?
    By Renejorgensen in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-23-2016, 10:54 AM
  3. [SOLVED] Index / Match - match 3 input values and return the results from the index
    By t83357 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-08-2016, 07:34 PM
  4. [SOLVED] Match-Index in stead of Index-Match lookup Array among Arrays
    By Numnum in forum Excel General
    Replies: 2
    Last Post: 10-15-2015, 02:08 PM
  5. Replies: 6
    Last Post: 04-30-2014, 02:42 AM
  6. Replies: 6
    Last Post: 11-08-2013, 10:29 PM
  7. Replies: 3
    Last Post: 05-02-2013, 01:31 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