+ Reply to Thread
Results 1 to 20 of 20

Replace Index Match with VBA - Multiple Criteria - Thousands of rows and columns

  1. #1
    Registered User
    Join Date
    09-29-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Office 2013
    Posts
    13

    Replace Index Match with VBA - Multiple Criteria - Thousands of rows and columns

    Hello everyone. I have been a member of this site for almost 2 years and have learned a ton! Unfortunately I am venturing into VBA and have not found a solution for what I want.
    I have an excel sheet I use to track and employees absence. I will explain what I currently do so you have an idea.
    On the Month tab ie JAN, I paste in information from a report, each day I paste on the next empty line the new days absenteeism report and do that each day.
    I have created code on the monthly tab that converts the pasted date into something I can index/match and paste the results into the EMER tab which is like a 365 day calendar so we can track Absenteeism and look for patterns.

    What I currently have works well, and does exactly what I want, but with 1500 rows and 366 columns , but it is 550K cells filled with code which is slow.

    I currently use this code: =IFERROR(INDEX(JAN!$J$1:$J$3000,MATCH(1,(JAN!$G$1:$G$3000=Q$1)*(JAN!$A$1:$A$3000=$B10),0)),"") entered with CTRL+ALT+Enter. into 550K cells in the EMER tab.
    The code is adjusted 12 times, once for each month.
    The above code is easy to enter as I can drag across and down, but it needs to be different for each month and the Info I paste for each month is on a different tab.

    I will explain the code above.
    INDEX(JAN!$J$1:$J$3000 - This is the information I want pasted in each cell ie "E", "T", "NC", and others if I add
    MATCH(1,(JAN!$G$1:$G$3000=Q$1) - This matches the date in JAN $G$1:$G$3000 with the date in the first row of each column IE: EMER $Q$1
    *(JAN!$A$1:$A$3000=$B10) - This match the employee name in JAN A1:A3000 with the name in EMER $B$10:$B$1510


    I would like to be able to do this with VBA for many reasons including, size, speed and ease of use and updating requirements as they change.

    I have attached an extremely small version of my tracker, and changed the names etc as this is a sensitive document.

    I appreciate any and all assistance
    Attached Files Attached Files

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: Replace Index Match with VBA - Multiple Criteria - Thousands of rows and columns

    Hi jaybrd1,

    I agree that so many CSE formula cells in a workbook AND lots of Conditional Formatting cells will slow your work down. Have you considered showing all your information using Pivot Tables?? If you keep all your CSE formulas it will never speed up.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Registered User
    Join Date
    09-29-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Office 2013
    Posts
    13

    Re: Replace Index Match with VBA - Multiple Criteria - Thousands of rows and columns

    Yes, I have played with it. Unfortunately, the presentation is important, as we have 30 managers who look at this sheet daily and it is updated daily by myself, but could move to someone else.
    Each month needs to be separated, and each instance of an absent an what it was for needs to stand out so we can see patterns immediately. The employee list changes daily as do the absences.

    We are set on the design, unless you can show a pivot table that updates how I have it now, and retains the visual style. Even if I were to use a Pivot table, I still need to lookup each individual absence for every day of the year for up to 1500 employees which gets posted into the monthly tabs, which already has codes in them to make the data compatible with the Vlookups and the information we want to show.

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: Replace Index Match with VBA - Multiple Criteria - Thousands of rows and columns

    If you combine all your monthly sheets onto a single one, I believe Pivots could give you more information than you have now. I'm positive it would be much faster.

    You can Group Dates and have filters by department or by type or category much easier with a Pivot.

    Look at
    http://chandoo.org/wp/2009/11/17/gro...-pivot-tables/ or
    http://fiveminutelessons.com/learn-m...el-pivot-table

    You didn't really give us enough data to show what Pivots can do..

  5. #5
    Registered User
    Join Date
    09-29-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Office 2013
    Posts
    13

    Re: Replace Index Match with VBA - Multiple Criteria - Thousands of rows and columns

    Marvin, I am afraid I cannot provide the live document...legally. It contains real people information.
    I did go look at the pivot tables again including the links you provided. If I was looking to for a report they would be good, but we need something straight forward a visually shows each day and each employee.

    I am getting a little confused as even if I went to a pivot table, I would still need to have a table filled with data which still needs to be entered the same way I do it now.

    How will a pivot table make entering the data any quicker?
    What I am looking for is a quicker was to fill the table with data. When took this document over they were entering all this data individually employee by employee at times taking hours. I automated it so I just need to paste in our absenteeism report and everything auto populates. I thought finding a VBA solution would speed things up by not having half a million lines of code running every time I paste something.

  6. #6
    Registered User
    Join Date
    09-29-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Office 2013
    Posts
    13

    Re: Replace Index Match with VBA - Multiple Criteria - Thousands of rows and columns

    I have attached a copy with more data so you can see what I mean about patterns etc. Most of the people using this document come to look at for info, not to analyze it. Seeing the pretty colors and patterns is what helps, not the numbers themselves, although they do need those as well.

    What I am looking for is a way to enter the code I need to put in each little cell as VBA instead of array formulas.
    Attached Files Attached Files

  7. #7
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,412

    Re: Replace Index Match with VBA - Multiple Criteria - Thousands of rows and columns

    Hi,
    Here's a suggestion using VBA.

    Note that I used your first file to make this macro and it will only compile JAN and FEV for demonstration purpose. I don't have time to continue it this morning but as you can see this can be pretty fast.
    Attached Files Attached Files
    GC Excel

    If this post helps, then click the star icon (*) in the bottom left-hand corner of my post to Add reputation.

  8. #8
    Registered User
    Join Date
    09-29-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Office 2013
    Posts
    13

    Re: Replace Index Match with VBA - Multiple Criteria - Thousands of rows and columns

    Thanks GC Excel, I looked at it and I think I understand what you have done, but I am not actually seeing the "E", "T" or "NC" showing up on the EMER tab.
    When I look at the code, I can see you referenced columns 1, 7 and 10, which is the Name, Date and Status (status is what should show on the EMER tab). I understand I will need to make one for each month, I can do that.
    On the "write back to sheet" portion of the code I can see you are using lines 23-32, which you added names to. This part confuses me a bit, but I think I can see what it is doing.

    Unfortunately, I do not see it writing back to the EMER tab.

  9. #9
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,412

    Re: Replace Index Match with VBA - Multiple Criteria - Thousands of rows and columns

    Hi,
    Sorry, I was in a hurry this morning when I sent you the code.
    I forgot to say that you need to click on the button to run the macro.
    I used the names in rows 23 to 32 to test and compare the results with the names in rows 10-19. You can change the loop and delete those names I added.

    Here's an updated version of the code, that will loop through all sheets. Change the values of shNames as required.

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    09-29-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Office 2013
    Posts
    13

    Re: Replace Index Match with VBA - Multiple Criteria - Thousands of rows and columns

    I tested it on a fresh copy with real data, and I first encountered:

    Run-time error '457': This key is already associated with an element of this collection.
    After looking up that error, I determined it was due to having multiple entries where the name and date were the same. I removed those as I really do not want duplicates.

    I then got:
    Run-time error '13': Type mismatch

    I looked up this error but got lost

    Debugging highlights this line:

    'Populate dictionary
    For i = 1 To UBound(ar, 1)

    I get the error whether running in the VBA application or pressing the button I made to run the macro.

    Here is the exact code I used with the adjustments:

    Please Login or Register  to view this content.
    Last edited by jaybrd1; 04-29-2014 at 04:29 PM.

  11. #11
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,412

    Re: Replace Index Match with VBA - Multiple Criteria - Thousands of rows and columns

    In VBE, go in Display and show the Local Variable Window
    The run the code.
    When it stops, do you have any values in the variable "ar" (you should have a + sign to expand it)

    In your months sheets, does your list always start in cell A1??
    I used ar = ws.cells(1).currentregion.value. So this assumes there is a value in A1.

    Check that and let me know.

  12. #12
    Registered User
    Join Date
    09-29-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Office 2013
    Posts
    13

    Re: Replace Index Match with VBA - Multiple Criteria - Thousands of rows and columns

    I "think" I ran the Local Variable window, which I think is called Watch in 2013. When I tried the first time, there was no plus"
    Expression: ar
    Value:Empty
    Type: Variant/Empty
    Context: Module1.Compile

    I then tried adding headers and of course the plus sign showed and each ar had 3K lines, it showed the header on the first line, and for the rest of the rows, columns A,B,C,D,E,F (1-6) were empty, column G (7) showed a date from the formula there and columns H,I,J (8-10) showed "".

    When I added the header (which I do not use, all data should go into A1:F1 and down, the Run-time 13 error went away, but the Runtime Error 457 returned.

    I really want to thank you for taking the time with me here, I admit I am brand new to VBA, just self learning.

    I have reverted back to the original.

  13. #13
    Registered User
    Join Date
    09-29-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Office 2013
    Posts
    13

    Re: Replace Index Match with VBA - Multiple Criteria - Thousands of rows and columns

    Ok, GC, I played with it more and actually found the right window. The ar has no plus sign beside it. the other variables can be expanded, but not ar.
    Module1 has a plus
    Dic has a plus
    shNames has a plus
    ws has a plus

    Dict, ar, I,n,j,sName,rg and c do not have a plus.

    As I said all data should start on A1, this could be changed. Currently I only placed data in the JAN tab until we get it working.

    Edit:
    I added a line to Feb as it seems that was where it was getting the error. Now I am back to the Runtime 457 error, that was due to a duplicate date, I changed it and MAR was the culprit tab.
    I added a line to each month and now it works!

    Does this mean I will need to make a fictitious person to start each month or it will not work? Normally those tabs would stay empty until the start of the month.
    Last edited by jaybrd1; 04-29-2014 at 07:25 PM.

  14. #14
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,412

    Re: Replace Index Match with VBA - Multiple Criteria - Thousands of rows and columns

    Hi,
    If your data starts in A1 and it is a header (same for each sheet) then replace

    Please Login or Register  to view this content.
    with

    Please Login or Register  to view this content.
    As you found out, you can not have duplicate keys in a dictionary. So you need to exclude the header from the compilation by starting in row 2.

  15. #15
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,412

    Re: Replace Index Match with VBA - Multiple Criteria - Thousands of rows and columns

    Edit:
    I added a line to Feb as it seems that was where it was getting the error. Now I am back to the Runtime 457 error, that was due to a duplicate date, I changed it and MAR was the culprit tab.
    I added a line to each month and now it works!

    Does this mean I will need to make a fictitious person to start each month or it will not work? Normally those tabs would stay empty until the start of the month.
    I just saw your last post, so what I just said probably does not make sense.
    When the code stops, click debug then hover your mouse on the line highlighted in yellow.

    It should break at :

    Please Login or Register  to view this content.
    if you place the cursor over ar(i, 1), ar(i, 7) and ar9(i, 10), what values do you see?

  16. #16
    Registered User
    Join Date
    09-29-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Office 2013
    Posts
    13

    Re: Replace Index Match with VBA - Multiple Criteria - Thousands of rows and columns

    I have currently added a fictitious name to each month and that fixed the error. When I remove the fictitious name I do not get an error on the line you proposed, I only get one there if there is a duplicate name with the same date.
    I still only get the error For i = 1 To UBound(ar, 1) when the first line is empty, and of course that is the Runtime error 13, type mismatch error.
    When I hover over it:
    the i = 2977, UBound = UBound(ar,1)=<Type mismatch> , ar = Empty

    Does that help any?

  17. #17
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,412

    Re: Replace Index Match with VBA - Multiple Criteria - Thousands of rows and columns

    I'd need to see your file.

  18. #18
    Registered User
    Join Date
    09-29-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Office 2013
    Posts
    13

    Re: Replace Index Match with VBA - Multiple Criteria - Thousands of rows and columns

    I wish I could Unfortunately it is filled with real information of employees and personal information. I cannot share it for ethical and legal reasons.
    Once I remove the 700 employees the document is again like the one I originally posted which I know does not show the proper information.

  19. #19
    Registered User
    Join Date
    09-29-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Office 2013
    Posts
    13

    Re: Replace Index Match with VBA - Multiple Criteria - Thousands of rows and columns

    I will be able to make this work and I thank you for all your assistance.
    I do have one last question though.
    The document size is currently 1 MB smaller, but it still takes forever to run the macro, is there any way to not have it run through every cell each time and only update if there is new data added?
    There will be times when I re-enter all the data for a given month, however that is not often.
    At this point the 550K lines of code was faster, I assume that will not be the case later in the year as more info is added.

  20. #20
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,412

    Re: Replace Index Match with VBA - Multiple Criteria - Thousands of rows and columns

    You could change the shNames variable to skip the past months and
    you can also change the rg variable to skip the past dates.

+ 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. VLookup or Index/match searching rows instead of columns or multiple criteria
    By Groovicles in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 11-16-2013, 05:00 PM
  2. [SOLVED] INDEX+MATCH with multiple criteria across both rows and columns
    By george_k in forum Excel General
    Replies: 3
    Last Post: 10-26-2012, 04:11 PM
  3. Index and Match with multiple columns/rows
    By fab121 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-18-2012, 02:33 PM
  4. [SOLVED] Index and Match Multiple Header (Rows) Criteria
    By dluhut in forum Excel General
    Replies: 7
    Last Post: 04-12-2012, 06:25 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