+ Reply to Thread
Results 1 to 5 of 5

vlookup on a different workbook with a variable sheet name

  1. #1
    Registered User
    Join Date
    05-23-2014
    Posts
    37

    vlookup on a different workbook with a variable sheet name

    Hi,

    I just started venturing into VBA so please excuse my ignorance. I'm trying to pull the data from a different workbook that will have the previous month as the sheet's name. I can't get the dynamic part of the code. Can someone please help to see what is wrong with the below syntax or if there's a better solution to this? Much appreciated.

    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: vlookup on a different workbook with a variable sheet name

    I think its the actual formula, you are looking in one column c (c1:c6), but your looking for an answer in column 6.
    Hope this helps

    Sometimes its best to start at the beginning and learn VBA & Excel.

    Please dont ask me to do your work for you, I learnt from Reading books, Recording, F1 and Google and like having all of this knowledge in my head for the next time i wish to do it, or wish to tweak it.
    Available for remote consultancy work PM me

  3. #3
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: vlookup on a different workbook with a variable sheet name

    You are trying to use an A1 style reference in an R1C1 formula as well (C1:C6), Do you need the indirect/concatenate stuff as well? Try something like:
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    05-23-2014
    Posts
    37

    Re: vlookup on a different workbook with a variable sheet name

    I thought the indirect/concatenate part was necessary but if it's not, I don't need it. I couldn't get your suggestion to work either though. On the actual spreadsheet, it translates into the following

    =IF(A2<>"",IFNA(VLOOKUP(A2,"'[Excel Workbook 2014.xlsm]" & sheetname & "'!C1:H6",6,FALSE),0),"")

  5. #5
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: vlookup on a different workbook with a variable sheet name

    Well the indirect/concatenate stuff is only neccessary if you want the reference to be "hard-typed", so if you insert/delete rows around that range it will adjust itself.

    Are you sure you copied it correctly, I just opened a new workbook, ran the code in post #3 and got:
    =IF(A2<>"",IFNA(VLOOKUP(A2,'[Excel Workbook 2014.xlsm]April'!C1:H6,6,FALSE),0),"")

  6. #6
    Registered User
    Join Date
    05-23-2014
    Posts
    37

    Re: vlookup on a different workbook with a variable sheet name

    I was embedding that into my existing macro and it didn't work but when I created a new macro, it ran. However, it requires me to choose the file from the directory even though the file is already opened. Is there a solution to that? Thanks.

+ 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: 4
    Last Post: 03-06-2014, 07:49 PM
  2. Vlookup From Closed Workbook with variable filename
    By wporter86 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 11-25-2013, 10:47 AM
  3. vlookup with variable workbook and sheet
    By nzeg in forum Excel General
    Replies: 4
    Last Post: 08-10-2009, 04:06 AM
  4. [SOLVED] selecting sheet name in another workbook by variable (same sheet name)
    By Craig in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-25-2006, 12:50 PM
  5. [SOLVED] VBA/Vlookup with workbook defined in a variable
    By HeatherO in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 02-09-2005, 05:06 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