Results 1 to 7 of 7

Using a VBA Vlookup macro when the filenames keep changing

Threaded View

2vbr Using a VBA Vlookup macro... 06-12-2021, 07:43 AM
a2b1c1d1e1f1 Re: Using a VBA Vlookup macro... 06-12-2021, 09:54 AM
ByteMarks Re: Using a VBA Vlookup macro... 06-12-2021, 10:06 AM
2vbr Re: Using a VBA Vlookup macro... 06-13-2021, 06:10 AM
ByteMarks Re: Using a VBA Vlookup macro... 06-13-2021, 08:24 AM
2vbr Re: Using a VBA Vlookup macro... 06-13-2021, 11:45 PM
ByteMarks Re: Using a VBA Vlookup macro... 06-14-2021, 04:22 AM
  1. #1
    Forum Contributor
    Join Date
    06-25-2017
    Location
    Australia
    MS-Off Ver
    365
    Posts
    102

    Question Using a VBA Vlookup macro when the filenames keep changing

    I use VLookup to copy data from column B in Spreadsheet 1 to Spreadsheet 2, and have recently made a macro to automate it.

    Problem is, the filename of Spreadsheet 1 changes constantly because it's an auto-generated report that adds the current date to the end of the filename, plus a suffix for every new report generated that day:

    Report2021-06-11.csv
    Report2021-06-11 (1).csv
    Report2021-06-11 (2).csv
    Report2021-06-11 (3).csv
    ...etc



    To get around this, I save the generated report using a generic filename (like Report.csv) and use this macro in Spreadsheet 2 to copy all the data in column B over:

          With Range("A2", Cells(Rows.Count, "A").End(xlUp))
        .SpecialCells(xlConstants).Offset(, 1).FormulaR1C1 = "=VLOOKUP(RC[-1],'Report.csv'!R2C1:R1048576C2,2,FALSE)"
      End With
    I'm just wondering if there's a way to cut out the "Save Spreadsheet 1 as Report.csv" step?

    Saving the auto-generated Spreadsheet 1 as Report.csv does the job and allows my macro to work. I'm happy about that. It just... would be nice if there was a fancy way to amend the macro so that step could be removed from the process. Although I can't imagine how, even if Excel was told to get the data from "Currently open Spreadsheet named "Report[Today's date]+[(Highest number, if any)]" That seems a little overly complex, and I don't know if Excel can do such a thing anyway?

    Is there a way to remove this step from the process? Or is this step the simplest method available, and I should just be happy it works?
    Last edited by 2vbr; 06-12-2021 at 07:46 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Restricting save filenames to stop changing the original file.
    By Mott31 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-22-2016, 02:55 PM
  2. Pass Filenames into Macro
    By CodyKL in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-29-2012, 11:38 AM
  3. Dynamic Filenames using the macro
    By lev_lev in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-19-2012, 05:23 PM
  4. vlookup syntax when using dynamic ranges and filenames
    By intothewild in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-27-2011, 04:54 AM
  5. Changing filenames ruin my macro
    By ExcelToyney in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-25-2010, 07:51 AM
  6. Replies: 9
    Last Post: 02-14-2009, 01:50 PM
  7. print pdf's with changing filenames in a macro
    By cjesag@aol.com in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-15-2006, 10:35 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