VBA Lookup from closed workbook

  • Hi All!


    Would like to ask for help on what I'm currently working.



    Sales_Conso.xlsm is my consolidating workbook. Range D8 to last column, contains the file names of the workbook where my table array will be.
    What I wanted to achieve is:
    If range D11 to last row is blank, it will open the workbook specified based on the file name on D8 and will apply the vlookup formula.
    Lookup_Value = Sales_Conso.xlsm range B8 to last row
    Table_Array = Filename on D8 to last column, range B7 to last cell with value
    Col_index_num = 10




    I've attached the sample files for everyone's reference.


    Hope someone could help.
    January 2019.xlsm.xlsx Sales_Conso.xlsx

  • Hi


    Try the following. I have noticed an issues with your file extension (why you do have January 2010.xlsm.xlsx) . This needs to be corrected. Or change the file names on row 8.





    Regards


    Maqbool

  • Hi Maqbool!


    The code works! Thank you very much.


    However, its only applying on row 11. Can I also apply the same on the rows below?


    Appreciate your help on this.

  • Hi


    Change the code as below:



    Regards


    Maqbool

  • Hi Maqbool!


    The code is now working but I noticed the following:

    strSht = "Master Data'!$B$7:$K$33,10,FALSE)" - is there a way that $B$7:$K$33 be dynamic? Like $B7 to lastrow?
    .Cells(n, x).Value = "=VLOOKUP($B11," & strlkparray - would also need $B11 to be dynamic. The lookup_array should be like B11, B12, B13.. and so on Thank you very much for your help.

  • Hi


    Code below will solve both issues:


    Please leave blank row 1 on consolidation workbook.



    Regards


    Maqbool

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!