+ Reply to Thread
Results 1 to 5 of 5

Pulling data from another workbook, which name depends on cell

  1. #1
    Registered User
    Join Date
    07-07-2020
    Location
    Panama
    MS-Off Ver
    365
    Posts
    5

    Pulling data from another workbook, which name depends on cell

    I receive 15 excel files with data every 15 days and I need to consolidate the summaries of all files into an excel, and also retain the previous files that were sent.

    The names of the files I receive are in the same format, so they are predictable. I'm trying to write a Macro that pulls data from those files, where the names of the files depend on the value of some cells. Basically I need to do a VLOOKUP to pull data from another workbook that I may or may have not received yet, but I can predict the name of the file. However, I'm having trouble for my code to work.

    For the purpose of this example, I'm just running one step of the loop because it's not working with one step. I would also like the macro to skip to the next item in the loop if it doesn't find the file.

    Here is my code:

    Please Login or Register  to view this content.

    I get an runerror type 'Mismatch'

    I'm attaching two workbooks to serve as samples. For the first iteration of my code I want the output to be on cell D6 on Sheet1 of workbook "Excel Macro Problem".

    It should return the value on cell K27 on sheet "XXX" of workbook "SAN MIGUELITO JUNIO 2020", by doing a VLOOKUP and finding a match between cell C6 on "Excel Macro Problem" with cell J27 on "SAN MIGUELITO JUNIO 2020".

    Thanks in advance for any help!
    Attached Files Attached Files
    Last edited by lecorrea; 07-07-2020 at 08:12 PM. Reason: Attaching Excel workbooks

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Pulling data from another workbook, which name depends on cell

    Administrative Note:

    Hi and welcome to the forum.

    We would very much like to help you with your query, however our rules require that code should include code tags around it.

    Please see Forum Rule #2 about code tags. More information about these and other tags can be found here

    Since this is your first post I'll add them for you.

    In addition please upload your actual workbook so that we can see in context.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    07-07-2020
    Location
    Panama
    MS-Off Ver
    365
    Posts
    5

    Re: Pulling data from another workbook, which name depends on cell

    Thanks for the feedback! I was not aware of how to show the code in that format. I went ahead and edited the post to include two sample workbooks so you can further help me with my problem. Thanks!

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Pulling data from another workbook, which name depends on cell

    Please Login or Register  to view this content.
    should be
    Please Login or Register  to view this content.
    WorksheetFunction.VLookUp raises run time error when it doesn't find the match, so
    Please Login or Register  to view this content.
    as Ret is variant type, it could receive the error value instead of run time error.

    However, given the path & workbook name & sheet name & range, you could use ExecuteExcel4Macro to calculate the results.
    So no need to open.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    07-07-2020
    Location
    Panama
    MS-Off Ver
    365
    Posts
    5

    Re: Pulling data from another workbook, which name depends on cell

    Thanks a lot, that code worked!

+ 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. ExecuteExcel4Macro Pulling data from a Cell in Closed Workbook - slow for large File :(
    By Doc.AElstein in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-21-2016, 12:35 PM
  2. Ms access Vba Save Data to xl depends upon 1 table pick & Depends 2 Upon fiterDate
    By breadwinner in forum Access Programming / VBA / Macros
    Replies: 14
    Last Post: 05-29-2014, 10:59 PM
  3. [SOLVED] VBA pull data from closed workbook depends upon header status !!! need help of experts
    By johnodys in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-12-2013, 07:06 AM
  4. Pulling a Specific Cell when Pulling a Tabel from Web Based Data
    By Zallen89 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-26-2013, 05:39 PM
  5. [SOLVED] fill column with vlookup formula to other workbook that depends on cell value
    By knick12 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-23-2012, 03:11 AM
  6. Replies: 5
    Last Post: 09-30-2008, 06:38 AM
  7. Replies: 3
    Last Post: 09-30-2008, 04:58 AM

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