+ Reply to Thread
Results 1 to 3 of 3

VBA Index Match Odd Fault

  1. #1
    Registered User
    Join Date
    04-04-2016
    Location
    Washington, DC
    MS-Off Ver
    2013
    Posts
    10

    VBA Index Match Odd Fault

    I am having an issue with a tool that does a lot of data parsing and tracking... But I have run into an issue I have never experienced.

    Detail.jpg

    On a dashboard is a table that lists 10 items with 6 columns of data points. The table is scroll-able using an offset formula.
    When the form control button in the Detail column is selected for each row, a user form opens with the task details and a couple of simple buttons. When the form opens, there is a simple VBA code written to populate a text box using an index match with whatever task number is the respective ID # column with the details of that task from a separate table on a different tab.

    The issue is that when I select the details button for any row, the first instance of the text box population is always blank...

    Select1.JPG

    But when the form is closed and the same line is selected again, it populates the correct details...

    Select2.JPG

    And if I move down to the next item, the first time the form populates it does so with the previous task details, and on the second population it opens with the correct details.

    I have checked the index and matching ranges multiple times, tried cell and range specifications for the match criteria, nothing seems to work. I also have code written to clear the text box on the form every time it is closed. Still nothing seems to change.

    Below is the VBA being used... There would be 10 subs for the 10 different index match options.

    Sub Detail1()
    Dim sws As Worksheet
    Dim dws As Worksheet
    '//Set elements
    Set sws = ThisWorkbook.Worksheets("ORDER DATA PARSED")
    Set dws = ThisWorkbook.Worksheets("Dashboard")
    UserForm1.Show
    UserForm1.TextBox1.Value = (Application.WorksheetFunction.Index(sws.Range("ODataP[Detail]"), Application.WorksheetFunction.Match(dws.Range("$C$41").Value, sws.Range("ODataP[INDEX ID]"), 0), 1))
    End Sub

  2. #2
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: VBA Index Match Odd Fault

    If your form is modal, then the code actually stops when it is first shown, so the textbox is not populated at that point.
    Rory

  3. #3
    Registered User
    Join Date
    04-04-2016
    Location
    Washington, DC
    MS-Off Ver
    2013
    Posts
    10

    Re: VBA Index Match Odd Fault

    Ah! So it is a matter of placing the population code before the show line... Like this:

    Sub Detail1()
    Dim sws As Worksheet
    Dim dws As Worksheet
    '//Set elements
    Set sws = ThisWorkbook.Worksheets("ORDER DATA PARSED")
    Set dws = ThisWorkbook.Worksheets("Dashboard")
    UserForm1.TextBox1.Value = (Application.WorksheetFunction.Index(sws.Range("ODataP[Detail]"), Application.WorksheetFunction.Match(dws.Range("$C$41").Value, sws.Range("ODataP[INDEX ID]"), 0), 1))
    UserForm1.Show
    End Sub

    Just tested it out and it works perfect every time! Thank you!!!

+ 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 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
  2. [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
  3. [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
  4. INDEX MATCH MATCH/OFFSET MATCH MATCH with named ranges
    By Andrew-Mark in forum Excel General
    Replies: 3
    Last Post: 02-27-2015, 10:56 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