+ Reply to Thread
Results 1 to 17 of 17

index/match array vba

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-22-2013
    Location
    Sibiu
    MS-Off Ver
    Excel 2007
    Posts
    114

    index/match array vba

    Sub test1()
        Dim testing As Integer
        Dim region As Range
        Dim region2 As Range
        Dim region3 As Range
        Dim i As Integer
        Dim j As Integer
        Dim k As Integer
        
        i = 0
        j = 0
        k = 0
        
        For j = 0 To 11
         For i = 0 To 11
             For k = 0 To 5
             
        Worksheets("Lista_lunara_repere").Activate
        
        Set region = ActiveSheet.Range(Cells(11, i * 6 + 5), Cells(50, i * 6 + 9))
        Set region2 = ActiveSheet.Range(Cells(11, i * 6 + 5), Cells(55, i * 6 + 5))
        Set region3 = ActiveSheet.Range(Cells(11, i * 6 + 9), Cells(55, i * 6 + 9))
           
        Worksheets("TestMacro").Activate
        testing = Application.index(region, Application.Match(Cells(j * 16 + 3, 3) & Cells(j * 16 + 3, k * 1 + 4), region2 & region3, 0), 4)
        
       Cells(j * 16 + 4, 4).Value = testing
        
             Next k
         Next i
      Next j
    End Sub

    Hello,
    I am trying to replace a lot of index forumlas that have started to slow my workbook down quite a lot with a macro that i hope will help me reduce "operating" time.
    This setup works up untilli added another condition and another range for the match part wich i guess turned the "formula" into an array. Now i get a run-time error '13': type mysmatch. Help preety plz.
    Last edited by a.hudrea; 02-10-2014 at 06:01 AM.

  2. #2
    Forum Contributor
    Join Date
    07-22-2013
    Location
    Sibiu
    MS-Off Ver
    Excel 2007
    Posts
    114

    Re: index/match array vba

    Tried to find some solutions and found out that for array formulas to work in vba you need to change the reference style to r1c1 so I added
        Dim originalReferenceStyle
        originalReferenceStyle = Application.ReferenceStyle
        Application.ReferenceStyle = xlR1C1
    but now i get and compile error: sub or function not definded and it points at region2 in the match formula.

  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: index/match array vba

    It is not possible to join arrays using & in VBA, nor to use them in Match like this. You may either loop through ranges or create formula string to use with Evaluate method.
    • Please remember to mark threads Solved with Thread Tools link at top of page.
    • Please use code tags when posting code: [code]Place your code here[/code]
    • Please read Forum Rules

  4. #4
    Forum Contributor
    Join Date
    07-22-2013
    Location
    Sibiu
    MS-Off Ver
    Excel 2007
    Posts
    114

    Re: index/match array vba

    if it's possible could you show me a small example? please

  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: index/match array vba

    It will be like this:
    testing = Application.Evaluate("INDEX(Lista_lunara_repere!" & region.Address & ",MATCH(" & Cells(j * 16 + 3, 3).Address & "&" & Cells(j * 16 + 3, k * 1 + 4).Address & "," & region2.Address & "&" & region3.Address & ", 0), 4)")

  6. #6
    Forum Contributor
    Join Date
    07-22-2013
    Location
    Sibiu
    MS-Off Ver
    Excel 2007
    Posts
    114

    Re: index/match array vba

    I have tried a few options, nothing worked, i only started to work with vba for 2 weeks and a lot of stuff is new to me. I have attached an example of how i would like my excel to be. In this state it works fine, but the issue is that with the current macro i only get the first item that it finds. If i want the second one i would have to add another criteria and another range in the match subthingy. If i do that it will transform it into an array and this is where things exceed my knowledge.

    Book1.xlsm

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

    Re: index/match array vba

    Please explain what it is you want to see as output and why you may not simply use formulas.

  8. #8
    Forum Contributor
    Join Date
    07-22-2013
    Location
    Sibiu
    MS-Off Ver
    Excel 2007
    Posts
    114

    Re: index/match array vba

    What i need in the end is this:
    - from the book1 example i want the quantity in m the I multiply it with the price that i get from another index and i get a product. That would be the ammount that i have spent for a quantity from a certain suplier. And at the very end I need to see how much i have saved (or not) by choosing on suplier over a standard price set by the board.The thing is that i have a lot of products and a lot of supliers + 12 months that results in hundreds maybe thousands of cells being populated with array formulas and that slows the workbook alot.
    Thats why I am trying to setup this macro to see if it can do it faster. The workbook with formulas is already working but its slow and it will only get slow with every extra product and suplier.

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

    Re: index/match array vba

    You have said:
    with the current macro i only get the first item that it finds. If i want the second one i would have to add another criteria and another range in the match subthingy
    This is what I seek to clarify - I do not know what you want.

  10. #10
    Forum Contributor
    Join Date
    07-22-2013
    Location
    Sibiu
    MS-Off Ver
    Excel 2007
    Posts
    114

    Re: index/match array vba

    I want the quantity of the code "222" in relation with each suplier. So from January i need the quantity of 222 from "first" suplier and the quantity of 222 from "third" suplier.
    So in Sheet "Results" C6 i want the quantity of 222 from the first suplier D6 quantity of 222 from second if there is any and so on.
    Last edited by a.hudrea; 02-11-2014 at 05:30 AM.

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

    Re: index/match array vba

    Only for code 222?

  12. #12
    Forum Contributor
    Join Date
    07-22-2013
    Location
    Sibiu
    MS-Off Ver
    Excel 2007
    Posts
    114

    Re: index/match array vba

    for all codes, every month and suplier but i would do that with for .. next. i will try to edit an dexample of how it looks like with formulas.

  13. #13
    Forum Contributor
    Join Date
    07-22-2013
    Location
    Sibiu
    MS-Off Ver
    Excel 2007
    Posts
    114

    Re: index/match array vba

    =IFERROR(INDEX(January;MATCH(111&"First";January_code&January_suplier;0);4)*INDEX(Acquisition;MATCH(111&January_price;Acquisition_code&Acquisition_month;0);VLOOKUP("First";Suplier_list;2;FALSE));0)
    first index gets me quantity, seconde index gets me the price for that code in the month of january. I can get to the other codes, supliers and months by using for .. next.

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

    Re: index/match array vba

    I think your formulas will be much faster if you will create key columns instead of trying to join them inside array formulas.

  15. #15
    Forum Contributor
    Join Date
    07-22-2013
    Location
    Sibiu
    MS-Off Ver
    Excel 2007
    Posts
    114

    Re: index/match array vba

    I have tried, but the thing is at the end of the day i need to do it by those criterias.

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

    Re: index/match array vba

    I understand your criteria but if you will create one column in the source tables which concatenates the criteria fields, you will not require array formulas and they will perform better.

  17. #17
    Forum Contributor
    Join Date
    07-22-2013
    Location
    Sibiu
    MS-Off Ver
    Excel 2007
    Posts
    114

    Re: index/match array vba

    It may sound silly but ... i did not know you can use match with concatenate this gave me a whole new perspective on my macro :D ty so much.

+ 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: 04-30-2014, 02:42 AM
  2. [SOLVED] Index Match Array
    By namluke in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-02-2014, 09:55 AM
  3. Index Match array equation with sub-array calculation
    By glebbo in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-04-2012, 03:04 AM
  4. Nested Match(index()) vs. Match() array formula.
    By GeneralDisarray in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-14-2011, 07:57 AM
  5. Using Match/Index on 2d Array
    By ExcelMonkey in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-21-2006, 09:30 AM

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