+ Reply to Thread
Results 1 to 4 of 4

Macro to insert column, populate column with filename and merge all excel files in folder

  1. #1
    Registered User
    Join Date
    09-15-2016
    Location
    Amsterdam, Netherlands
    MS-Off Ver
    Microsoft Office Professional Plus 2010
    Posts
    10

    Macro to insert column, populate column with filename and merge all excel files in folder

    Hi everyone,

    I have been struggling with the following:

    I have a folder with over 100 excel files in it. I have found a macro that I have adjusted to make it merge the excel files into one worksheet:

    Please Login or Register  to view this content.
    What I would like to have this macro also do is insert a column in A with something like:

    Please Login or Register  to view this content.
    While also populating the column with the filename of the workbook the data comes from before copying it and moving on to the next file in the folder.

    Any help would be great!

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Macro to insert column, populate column with filename and merge all excel files in fol

    Activesheet.UserdRange might be better than Range("A1:IW" & lastrow) sort of range.

    I have not tested this but maybe:
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    09-15-2016
    Location
    Amsterdam, Netherlands
    MS-Off Ver
    Microsoft Office Professional Plus 2010
    Posts
    10

    Re: Macro to insert column, populate column with filename and merge all excel files in fol

    Thanks for your reply Kenneth. This does seem to do what I want in some way.It does add in the column and insert the file path and file name.

    I noticed that it did only copy the top row from each file and did not open all of the files in the folder.

    Any ideas?

  4. #4
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Macro to insert column, populate column with filename and merge all excel files in fol

    For the first, since the row was inserted, then one needs to get the number of rows in column B. Replace the commented line and add the other.
    Please Login or Register  to view this content.
    As for not iterating the other files, I would have to test. I don't see why it would not import the ThisWorkbook.Path files. Obviously, you need to to change that path to what you want if different. It could error on the 2nd file so uncomment the On Error line of code. Of course if it errors, you will need to run the ending Application lines in another Sub say to reset things.

    Of course it iterates all files but the macro's workbook so you need to be sure that is what you want.

+ 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: 1
    Last Post: 05-10-2019, 06:50 AM
  2. [SOLVED] merge column D from all csv files in folder to single master workbook
    By up&down in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-04-2014, 06:31 PM
  3. COPY PART OF FILENAME IN ALL EXCEL worksheet files IN A FOLDER
    By cds1 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-27-2014, 08:42 PM
  4. [SOLVED] populate combobox with files from folder but only excel files
    By jed38 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-30-2013, 02:31 PM
  5. Replies: 0
    Last Post: 03-04-2013, 02:37 PM
  6. [SOLVED] How to merge multiple excel files(xls) in one folder into a new xls file.
    By Hayk in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-24-2013, 11:48 AM
  7. Populate a Combo Box with the filename from a Folder in VBA?
    By Coume in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 08-17-2009, 08:38 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