+ Reply to Thread
Results 1 to 23 of 23

Macro with VLOOKUP on another WorkBook

Hybrid View

guibro Macro with VLOOKUP on another... 04-23-2015, 06:10 PM
humdingaling Re: Macro with VLOOKUP on... 04-27-2015, 01:02 AM
guibro Re: Macro with VLOOKUP on... 04-27-2015, 01:57 AM
humdingaling Re: Macro with VLOOKUP on... 04-27-2015, 02:14 AM
guibro Re: Macro with VLOOKUP on... 04-27-2015, 02:20 AM
humdingaling Re: Macro with VLOOKUP on... 04-27-2015, 02:25 AM
guibro Re: Macro with VLOOKUP on... 04-27-2015, 02:28 AM
guibro Re: Macro with VLOOKUP on... 04-27-2015, 02:29 AM
guibro Re: Macro with VLOOKUP on... 04-27-2015, 02:33 AM
humdingaling Re: Macro with VLOOKUP on... 04-27-2015, 02:40 AM
guibro Re: Macro with VLOOKUP on... 04-27-2015, 02:43 AM
humdingaling Re: Macro with VLOOKUP on... 04-27-2015, 02:50 AM
guibro Re: Macro with VLOOKUP on... 04-27-2015, 02:51 AM
guibro Re: Macro with VLOOKUP on... 04-29-2015, 12:16 PM
humdingaling Re: Macro with VLOOKUP on... 04-29-2015, 08:46 PM
guibro Re: Macro with VLOOKUP on... 04-30-2015, 12:37 AM
humdingaling Re: Macro with VLOOKUP on... 04-30-2015, 12:54 AM
guibro Re: Macro with VLOOKUP on... 04-30-2015, 11:53 AM
humdingaling Re: Macro with VLOOKUP on... 04-30-2015, 08:28 PM
guibro Re: Macro with VLOOKUP on... 05-01-2015, 12:51 PM
guibro Re: Macro with VLOOKUP on... 05-04-2015, 12:59 PM
guibro Re: Macro with VLOOKUP on... 05-04-2015, 11:45 AM
humdingaling Re: Macro with VLOOKUP on... 05-04-2015, 11:32 PM
  1. #1
    Registered User
    Join Date
    04-01-2015
    Location
    Seattle
    MS-Off Ver
    Last Mircrosoft office
    Posts
    65

    Macro with VLOOKUP on another WorkBook

    Hi Excel People,

    I have a template with a lot of Different Job Titles associated with Job functions. So for example, I have Director of Tax in Job Title, then the Job Function would be : Finance/Accounting. And I've done this matching with a lot and a lot of different Job Titles to Group them into fewer Job Function categories.


    My intent is then to populate different new files everyday by matching their Job Titles to the ones in the template and then returning the correct Job Function in those files.

    So I guess the correct way to do it is to have a VLOOKup in the Macro that looks for a similar or almost similar Job Titles in the Template and then returns the Job Function associated to it.


    Do you guys have any idea of how the macro would look like ?

    For the purpose of this experience, let's say the Column Index will always be the same but the number of cells within the columns could fluctuate.

    Thanks a lot and I look forward to exchanging with you about that.


    Cheers,

    -Guillaume

  2. #2
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Macro with VLOOKUP on another WorkBook

    what are you looking up against what?
    i dont see where the separate workbook comes into play?
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  3. #3
    Registered User
    Join Date
    04-01-2015
    Location
    Seattle
    MS-Off Ver
    Last Mircrosoft office
    Posts
    65

    Re: Macro with VLOOKUP on another WorkBook

    Thank you really much for the follow up Humdingaling.

    So I want to have a a workbook that's gonna serve as a bank. The workbook will have 2 columns : One with all the Job Titles that I could Have and in the 2nd one, all the Job Functions associated with those Job Titles.

    Then I'll have other worksheets on a daily basis, that I will have to populate. Those workbooks will have a Job Title column but a Job Function column empty.

    So I want the macro to run a Lookup of each Job Title in this workbook in the bank-workbook and return the job Function associated with it in the workbooks that I have to populate.

    Is it more clear ?

    Thanks a lot for your help and I stay tuned.


    Cheers,


    -guillaume

  4. #4
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Macro with VLOOKUP on another WorkBook

    ok
    that makes sense
    cant you just put the vlookup (use the whole column) in and leave it? save a different version if you want it hardcoded version?
    that way no need for macro/VBA? or am i missing something?

  5. #5
    Registered User
    Join Date
    04-01-2015
    Location
    Seattle
    MS-Off Ver
    Last Mircrosoft office
    Posts
    65

    Re: Macro with VLOOKUP on another WorkBook

    The thing is that I want to automate few tasks on multiple workbooks at once. I already have a macro that Proper my first 2 columns of every open workbooks. I want to add this macro which will populate every Job Functions of my all my open workbooks based on the relationship (in the bank workbook) that i just explained.

    So by one click, the macro will search for the same job title in the bank workbook and return the Job function associated to it.

    Does that make sens to you ?

  6. #6
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Macro with VLOOKUP on another WorkBook

    ok sure no problem

    what is the workbook called?
    will the workbook be open when you run the macro or you want the macro to open it as well?

    what is the cell of the first formula
    assume you want it to auto fill formula as well?

  7. #7
    Registered User
    Join Date
    04-01-2015
    Location
    Seattle
    MS-Off Ver
    Last Mircrosoft office
    Posts
    65

    Re: Macro with VLOOKUP on another WorkBook

    The book hasn't got a name so far. So whatever you choose, I could put it after.

    And yes please, open the workbook would be great. But if I run the macro multiple times, is it problem if the macro tries to open something already opened ? if it is, don't worry about opening the workbook, i'll do it by myself when I need to.

    Million thanks for your help.

  8. #8
    Registered User
    Join Date
    04-01-2015
    Location
    Seattle
    MS-Off Ver
    Last Mircrosoft office
    Posts
    65

    Re: Macro with VLOOKUP on another WorkBook

    The book hasn't got a name so far. So whatever you choose, I could put it after.

    And yes please, open the workbook would be great. But if I run the macro multiple times, is it problem if the macro tries to open something already opened ? if it is, don't worry about opening the workbook, i'll do it by myself when I need to.

    Million thanks for your help.

  9. #9
    Registered User
    Join Date
    04-01-2015
    Location
    Seattle
    MS-Off Ver
    Last Mircrosoft office
    Posts
    65

    Re: Macro with VLOOKUP on another WorkBook

    Sorry for the duplicate messages... Internet issues...

    So for the workbooks that's gonna serve as as bank : i'll have Job titles in column A and Job Function in column B.

    For the workbooks that I want the run macro in, let's say the Job Title will be in column D starting in D2 and the Job Function would need to be in column E, so starting E2.

    Will it be easy to make the changes of that cell references in the future ?

    thanks a lot

  10. #10
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Macro with VLOOKUP on another WorkBook

    ok i can give you the rough guide

    basically you will need to fill in the "right" formula afterwards though

    Sub Insert_Vlookup()
    '
    '
        Dim ws1 As Worksheet
        Dim wb1 As Workbook
        
        Set wb1 = ThisWorkbook
        Set ws1 = ActiveSheet
        
        Workbooks.Open Filename:="C:\test.xlsx"
        wb1.Activate
        ws1.Range("C2").Formula = "=VLOOKUP(A2,'[test.xlsx]Sheet1'!$A:$C,3,0)"
        
    End Sub

  11. #11
    Registered User
    Join Date
    04-01-2015
    Location
    Seattle
    MS-Off Ver
    Last Mircrosoft office
    Posts
    65

    Re: Macro with VLOOKUP on another WorkBook

    Perfect, I'll try that at work Tuesday and I will definitely let you know.

    Thanks for your help on this.

    Is the Vlookup doing the matching but also returning the value in the workbook ?

    Also how can I add a loop so that it does the same on every files opened ?

    thanks.

  12. #12
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Macro with VLOOKUP on another WorkBook

    the code adds the formula into your worksheet
    you can change the workbook and worksheet it refers to

    as it is rough guideline just change to tailor to your needs

    Also how can I add a loop so that it does the same on every files opened ?
    would think it can be
    you would need to create a loop for all open workbooks

  13. #13
    Registered User
    Join Date
    04-01-2015
    Location
    Seattle
    MS-Off Ver
    Last Mircrosoft office
    Posts
    65

    Re: Macro with VLOOKUP on another WorkBook

    Awesome thank you.

    I keep you posted on tuesday.

  14. #14
    Registered User
    Join Date
    04-01-2015
    Location
    Seattle
    MS-Off Ver
    Last Mircrosoft office
    Posts
    65

    Re: Macro with VLOOKUP on another WorkBook

    Hi humdingaling ,


    So the macro does work perfectly.

    Just a few questions PLEASE:

    -How can I ask the macro to repeat the formula in all the non empty cells of the column ? So far, it is just doing the Vlookup for the first cell, the one that we put here : ws1.Range("C2").Formula

    -How can I ask the macro the run the same thing in all the open workbooks except the one called "test"?

    Thank you really much.


    -Guillaume

  15. #15
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Macro with VLOOKUP on another WorkBook

    How can I ask the macro to repeat the formula in all the non empty cells of the column ? So far, it is just doing the Vlookup for the first cell, the one that we put here : ws1.Range("C2").Formula
    you are going to be a bit more specific about this
    you want it to fill down but only for non empty?

    How can I ask the macro the run the same thing in all the open workbooks except the one called "test"?
    again not quite 100% sure what you are asking
    you want to vlookup formula in C2 on sheet1 of all workbooks open except test?
    if that is so you can run a loop thru all the open workbooks i guess
    let me know if this is exactly what you want

    Sub Insert_Vlookup()
    '
    
        Dim wb As Workbook
        
        Workbooks.Open Filename:="C:\Users\vthang\Downloads\Vlookup.xlsx"
        
        For Each wb In Workbooks
            If wb.Name <> "PERSONAL.XLSB" Then
                If wb.Name <> "Vlookup.xlsx" Then
            
                    wb.Activate
                    Range("C2").Formula = "=VLOOKUP(A2,'[vlookup.xlsx]Sheet1'!$A:$C,3,0)"
                End If
            End If
            
        Next wb
        
    End Sub
    Vlookup.xlsx is the file with the vlookup table
    Last edited by humdingaling; 04-29-2015 at 09:07 PM.

  16. #16
    Registered User
    Join Date
    04-01-2015
    Location
    Seattle
    MS-Off Ver
    Last Mircrosoft office
    Posts
    65

    Re: Macro with VLOOKUP on another WorkBook

    Thank you for your time !

    [QUOTE=humdingaling;4059158]you are going to be a bit more specific about this
    you want it to fill down but only for non empty?

    It's exactly why I want. I want the macro to fill the whole column not just the first cell. It is actually just filling the cell C2 and not the ones below.


    [QUOTE= again not quite 100% sure what you are asking
    you want to vlookup formula in C2 on sheet1 of all workbooks open except test?
    if that is so you can run a loop thru all the open workbooks i guess
    let me know if this is exactly what you want [/QUOTE]

    Again, you understood it perfectly. So because you name the file with the vlookup table Vlookup.xlsx, I want the macro to run in every open workbooks except the one that is called Vlookup.xlsx.

    In your macro in your last message, what does the file Personal.xlsb have to ? is it the place when you store the macro so that you can run it in every document all the time ?

    I hope I could help you because you are really helping me. thanks a lot for that.

  17. #17
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Macro with VLOOKUP on another WorkBook

    ok fill down...to where?
    what is the relative row you want it to fill down to?
    is it the same all the time or different?...are you sure you only want non blanks rather than just all of them updated?
    the coding for one is easy and the other hard

    Re: personal.xlsb
    im not sure if you have it on your system or not
    it is basically where most people store their macro's and where i assumed you are storing yours
    as such you dont want add a vlookup on that so that was just to bypass it as well

  18. #18
    Registered User
    Join Date
    04-01-2015
    Location
    Seattle
    MS-Off Ver
    Last Mircrosoft office
    Posts
    65

    Re: Macro with VLOOKUP on another WorkBook

    Actually, do the simpler one. I guess it's the one that is going to update them all. I just prefer if it's blank, to return nothing than to put #N/A.

    I don't have a precise row for the fill down and it does change from one workbook to another. So fill down until the last non empty row. is that possible ? it's like the auto-fill tool that we can use when we click on the bottom left of the cell.

    And yes I do have a personal file. So that's ok for me, I already have 3 macros in that file that I use all the time on my workbooks.

    Thanks a lot !

  19. #19
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Macro with VLOOKUP on another WorkBook

    I don't have a precise row for the fill down and it does change from one workbook to another. So fill down until the last non empty row. is that possible ? it's like the auto-fill tool that we can use when we click on the bottom left of the cell.
    yes plausible but still need some relative guide on where to stop otherwise....1048576 rows will get filled...
    last row in column A? B?C? or just last used range/row on the sheet?
    i will assume match column A

    then code
    Sub Insert_Vlookup()
    '
    
        Dim wb As Workbook
        
        Workbooks.Open Filename:="C:\Users\vthang\Downloads\Vlookup.xlsx"
        
        For Each wb In Workbooks
            If wb.Name <> "PERSONAL.XLSB" Then
                If wb.Name <> "Vlookup.xlsx" Then
            
                    wb.Activate
                    Range("C2").Formula = "=VLOOKUP(A2,'[vlookup.xlsx]Sheet1'!$A:$C,3,0)"
                    Range(Cells(2, 3), Cells(Cells(Rows.Count, "A").End(xlUp).Row, 3)).FillDown
                    
                End If
            End If
            
        Next wb
        
    End Sub
    Last edited by humdingaling; 04-30-2015 at 08:32 PM.

  20. #20
    Registered User
    Join Date
    04-01-2015
    Location
    Seattle
    MS-Off Ver
    Last Mircrosoft office
    Posts
    65

    Re: Macro with VLOOKUP on another WorkBook

    I have a few issues... First, it doesn't auto fill until the last row of the column. Let's say, column H is for Job Title and I for Job Function. I want to auto fill column I until the last entry in column H.

    Second Issue, it's weird because when I run the macro, the same formula appears in My Personal.xlsb file. It doesn't do any harm but I'm like wondering why it creates the same formula it that template.

    Below is the macro I use. I've been also wondering to what Range("C2"). formula is supposed to refer to ? is that first cell where I want the formula to start populating ?

    Thank you so much for your help. I'm sure it's almost done...

    Sub Insert_Vlookup()
    '
    
        Dim wb As Workbook
        
        Workbooks.Open Filename:="C:\Users\guillaume.brovelli.c\Desktop\Vlookup.xlsx"
        
        For Each wb In Workbooks
            If wb.Name <> "PERSONAL.XLSB" Then
                If wb.Name <> "Vlookup.xlsx" Then
            
                    wb.Activate
                    Range("I2").Formula = "=VLOOKUP(H2,'[vlookup.xlsx]Sheet1'!$A:$B,2,1)"
                    Range(Cells(2, 3), Cells(Cells(Rows.Count, "I").End(xlUp).Row, 3)).FillDown
                    
                End If
            End If
            
        Next wb
        
    End Sub

  21. #21
    Registered User
    Join Date
    04-01-2015
    Location
    Seattle
    MS-Off Ver
    Last Mircrosoft office
    Posts
    65

    Re: Macro with VLOOKUP on another WorkBook

    It's working now ! I was able to make the couple changes needed for me.

    Million thanks for your help !!

    -Guillaume

  22. #22
    Registered User
    Join Date
    04-01-2015
    Location
    Seattle
    MS-Off Ver
    Last Mircrosoft office
    Posts
    65

    Re: Macro with VLOOKUP on another WorkBook

    Hi humdingaling ,

    Did you have a chance to take a last look at my project ?

    Thank you really much.

    -Guillaume

  23. #23
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Macro with VLOOKUP on another WorkBook

    sorry i havent been in office this week
    I dont have excel at home so cant look at it

    glad you got it to work

    cheers
    Hum

+ 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 across entire workbook macro
    By lulu319 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-23-2013, 02:10 PM
  2. Help with a vlookup through entire workbook macro
    By lulu319 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-23-2013, 02:08 PM
  3. Vlookup Macro(VBA) One Sheet to another or One Workbook to another
    By atul2582 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-30-2013, 03:36 AM
  4. Macro with VLookup pointing to a closed workbook
    By dagindi in forum Excel General
    Replies: 2
    Last Post: 02-04-2010, 06:15 PM
  5. 255 Character Truncation, Vlookup Macro vs. Opening Workbook Macro
    By jrew23@yahoo.com in forum Excel General
    Replies: 1
    Last Post: 02-26-2005, 02:06 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