+ Reply to Thread
Results 1 to 7 of 7

VLOOKUP using 2 workbooks that both change name regularly?

  1. #1
    Registered User
    Join Date
    09-21-2015
    Location
    London
    MS-Off Ver
    2013
    Posts
    25

    Question VLOOKUP using 2 workbooks that both change name regularly?

    Hi,

    I run a simple VLOOKUP using 2 workbooks. This has traditionally been done manually, but now I need to automate the process every month:

    I usually use something like,

    =VLOOKUP(D1,'[PD1_Book1_15-09-22.xls]Live'!$A:$A,1,0) ..on the current workbook called NW 01-09, worksheet name "Master", cell F1. I then copy the entire function down the column. The end result being a lot of #N/A's which I filter out immediately.

    The problem is both workbooks change their name regularly (eg.. "PD*_Book1_**-**-**.xls, in which case "Book1" is constant and NW **-**, in which case NW is constant)

    So with "Live" sheet active on "PD*_Book1_*.xls" I've tried this, but can't get it to work at all.

    Sub Lookup()
    myFileName = ActiveWorkbook.Name
    mySheetName = ActiveSheet.Name
    myRangeName = Range("A:A")

    Dim wb As Workbook
    For Each wb In Workbooks
    If wb.Name Like "NW*.*" Then
    wb.Activate
    Exit Sub
    End If
    Next

    Range("F1").Formula = "=VLOOKUP(A1,[" & myFileName & "]" & mySheetName & "!" & myRangeName & ",1,0)"

    End Sub

    I am totally lost on this one, any help would be great. If I can't get it to work on 1 cell, I have no clue how to fill all of them!

    The NW workbook will always be open as it's subject to a load of data cleaning via macro before we get to this point. I am happy for the PD*_Book1_**.xls to be opened now if it's easier. The data for lookup is on worksheet "Live"

    I'm new to vba, and think i've bitten off more than I can chew. Thanks in advance.
    Last edited by gabbana; 09-22-2015 at 09:39 AM.

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VLOOKUP using 2 workbooks that both change name regularly?

    Don't know if this helps in your situation. But when referencing workbooks, if you only have the two opened at the same time the first one opened can be reference as Workbooks(1) and the next as Workbooks(2). Also the workbook which houses the code can always be refered too as Thisworkbook.
    Last edited by JOHN H. DAVIS; 09-22-2015 at 10:24 AM.

  3. #3
    Registered User
    Join Date
    09-21-2015
    Location
    London
    MS-Off Ver
    2013
    Posts
    25

    Re: VLOOKUP using 2 workbooks that both change name regularly?

    Does that mean

  4. #4
    Registered User
    Join Date
    09-21-2015
    Location
    London
    MS-Off Ver
    2013
    Posts
    25

    Re: VLOOKUP using 2 workbooks that both change name regularly?

    Sorry John, my browser is playing up. Does that mean I could technically reference 3 workbooks at a time generically?

  5. #5
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VLOOKUP using 2 workbooks that both change name regularly?

    It means when you open the application the first workbook opened is Workbooks(1) in the workbooks collection and the next would be Workbooks(2) and so on.... If that helps too solve your referencing issue. Also the workbooks which houses the code can be referred too as Thisworkbook.

  6. #6
    Registered User
    Join Date
    09-21-2015
    Location
    London
    MS-Off Ver
    2013
    Posts
    25

    Re: VLOOKUP using 2 workbooks that both change name regularly?

    Thank you, i'm nearly there I think, just getting a different error now for an unrelated bit. Have posted a different thread.

  7. #7
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VLOOKUP using 2 workbooks that both change name regularly?

    You're welcome. Wish you well.

+ 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: 1
    Last Post: 06-18-2015, 12:36 AM
  2. A formula for accruing values that are regularly deleted?
    By Vern297 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 01-12-2015, 03:37 AM
  3. Going from excel to googledoc to googlecharts .. and updating it regularly
    By duffbeer911 in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 1
    Last Post: 05-05-2014, 06:53 AM
  4. Array of Worksheet Names to be Updated regularly from Web Query
    By Ham Goat in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-12-2013, 09:04 AM
  5. trasnferring values of a variable and putting it in another regularly
    By Abhie in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-19-2013, 03:40 AM
  6. Regularly updated time display: not working
    By madhg in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-22-2009, 03:43 AM
  7. Regularly used files
    By John Dean in forum Excel General
    Replies: 5
    Last Post: 04-15-2006, 04:20 PM

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