+ Reply to Thread
Results 1 to 2 of 2

Vlookup Macro to fetch data from another worksheet

Hybrid View

  1. #1
    Registered User
    Join Date
    02-26-2014
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    33

    Vlookup Macro to fetch data from another worksheet

    Hi All,

    I am trying to create a macro for vlookup. Each time the name of the source file changes. I dont want to update the formula everytime. So Iam trying to do a macro which will fetch the data from the file that the user mentions in the sheet2.

    I have attached the source file and the VLookup file. Now when I enter the source file path in sheet 2 of workbook "Vlookup", and then if I run the macro it should open the file and put the dates in Sheet1 (Columns "D" and "E") of workbook "Vlookup". The dates in the source file will be available in sheet 1(column F and H) of that workbook. Can you please help me?

    Thanks!
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Vlookup Macro to fetch data from another worksheet

    Sub MakeFormulas()
    Set sh = ThisWorkbook.Sheets(1)
    wbname = ThisWorkbook.Name
    With Application.FileDialog(msoFileDialogOpen)
      .InitialFileName = ThisWorkbook.Path & "\*.xls*"
      .Title = "Please Select a File"
      .AllowMultiSelect = False
      .Show
      If .SelectedItems.Count = 0 Then Exit Sub            ' User clicked cancel: Exit
         strfile = .SelectedItems(1)
    End With
    Set mybook = Workbooks.Open(strfile)
    SelFile = Right(strfile, Len(strfile) - InStrRev(strfile, "\"))
    Windows(wbname).Activate
    Range("D1:D6").Formula = _
    "=VLOOKUP($A1,'[" & SelFile & "]Sheet1'!$A$2:$F$13,6,)"
    Range("E1:E6").Formula = _
    "=VLOOKUP($A1,'[" & SelFile & "]Sheet1'!$A$2:$H$13,8,)"
    
    
    End Sub
    If solved remember to mark Thread as solved

+ 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: 0
    Last Post: 10-10-2013, 02:42 AM
  2. Fetch and plot data using VBA/Macro
    By someyoungguy in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-23-2013, 01:23 AM
  3. VLOOKUP using VBA to auto fetch data
    By RahulM in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-16-2013, 09:46 AM
  4. [SOLVED] Fetch Data from Last Row in a Worksheet
    By Floydlevedale in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-24-2012, 07:07 PM
  5. Need Excel VBA macro to fetch data from notepad
    By yourskarthik in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-03-2010, 02:00 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