+ Reply to Thread
Results 1 to 10 of 10

Code that will put the file name in the last column for multiple workbooks

  1. #1
    Registered User
    Join Date
    10-20-2016
    Location
    Pittsburgh
    MS-Off Ver
    2016
    Posts
    6

    Lightbulb Code that will put the file name in the last column for multiple workbooks

    Big props to whoever knows how to do this. I have are around 100 different workbooks that I want to add a column at the end to that adds the file name to each row. Instead of going into each workbook and manually adding the file name to the last column does anyone know a code that can do this automatically? I've spent way too much time trying to figure this out.

    Thank you!!!

  2. #2
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,521

    Re: Code that will put the file name in the last column for multiple workbooks

    Re: "add a column at the end to that adds the file name to each row."
    You can't add a Column at the end. Excel 2007 and up have 16,384 Columns. That's it. Excel 2003 has 256 Columns
    You want to add the file name to, in Excel 2007 and up, over a million rows? (65,000+ in 2003)
    Are all the files in the same folder?
    Are there any other file types, .doc, .jpg, .pdf etc, in that same folder?
    Will the workbook with the code in it be saved in the same Folder?

  3. #3
    Registered User
    Join Date
    10-20-2016
    Location
    Pittsburgh
    MS-Off Ver
    2016
    Posts
    6

    Re: Code that will put the file name in the last column for multiple workbooks

    I meant the last column of the data set. So if its from A-N in column O. Files are in the same folder yes. They are all workbooks. Yes they will be saved in the same folder.

    Thanks!

  4. #4
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,521

    Re: Code that will put the file name in the last column for multiple workbooks

    Please Login or Register  to view this content.
    Last edited by jolivanes; 10-21-2016 at 12:34 PM. Reason: Missing period added

  5. #5
    Registered User
    Join Date
    10-20-2016
    Location
    Pittsburgh
    MS-Off Ver
    2016
    Posts
    6

    Re: Code that will put the file name in the last column for multiple workbooks

    Wow! thank you.

    So do I just put the folder the workbooks are located in where you wrote sheet1?

  6. #6
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,521

    Re: Code that will put the file name in the last column for multiple workbooks

    You don't have to change anything.
    Just make sure that all the workbooks, or files, are in the same folder, including the workbook, or file, with the code in it and that that has been saved in that folder.
    It will put the workbook name in Sheet1 of every workbook in that folder.
    Do a trial run first with some temporary workbooks if you don't quite follow the logic.
    Let us know if it all works to your liking.

  7. #7
    Registered User
    Join Date
    10-20-2016
    Location
    Pittsburgh
    MS-Off Ver
    2016
    Posts
    6

    Re: Code that will put the file name in the last column for multiple workbooks

    I have all the workbooks in one folder and I put a workbook called Book1 into that folder. But when I run the code in book1 I get a subscript out of range error. I tried running the code from one of the real workbooks too and it didn't work either. Any clue why?

  8. #8
    Registered User
    Join Date
    10-20-2016
    Location
    Pittsburgh
    MS-Off Ver
    2016
    Posts
    6

    Re: Code that will put the file name in the last column for multiple workbooks

    Got it to work! only problem is it writes the file name on the first row. Is there a way I can get it on every row of that column?

  9. #9
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,521

    Re: Code that will put the file name in the last column for multiple workbooks

    so you want the file name (=workbook name) in all the cells in that same column as far as the last used cell in the used range of that sheet?
    Change this line
    Please Login or Register  to view this content.
    to this
    Please Login or Register  to view this content.
    If you want it on every row(1 million+ for excel 2007 and up), let us know
    Last edited by jolivanes; 10-21-2016 at 04:22 PM. Reason: More info

  10. #10
    Registered User
    Join Date
    10-24-2020
    Location
    Prague
    MS-Off Ver
    2013
    Posts
    1

    Re: Code that will put the file name in the last column for multiple workbooks

    Re: Code that will put the file name in the last column for multiple workbooks

+ 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. Code to Extract data from multiple workbooks and Multiple sheet
    By Masa1989 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-04-2015, 07:05 AM
  2. [SOLVED] Consolidate all data in multiple worksheets of multiple workbooks in one Master file.
    By adil.master in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-23-2014, 09:59 PM
  3. Replies: 6
    Last Post: 02-28-2014, 09:34 AM
  4. [SOLVED] Need a batch file or VBA code to copy and rename a set of workbooks
    By ianpwilliams in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-03-2013, 05:06 AM
  5. [SOLVED] Run Same VBA Macro Code On Multiple Sheets of Multiple workbooks
    By AnnaDana in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 06-28-2013, 10:28 AM
  6. Replies: 3
    Last Post: 01-05-2013, 02:20 AM
  7. VBA code to update master file and reflect changes on other workbooks
    By Kimston in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-31-2012, 08:56 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