+ Reply to Thread
Results 1 to 6 of 6

Import multiple .TXT/.TAB files only using one header row

  1. #1
    Registered User
    Join Date
    05-01-2012
    Location
    Texas
    MS-Off Ver
    Excel 2010
    Posts
    10

    Import multiple .TXT/.TAB files only using one header row

    Hello,

    I am currently using VBA code to import multiple .txt and .tab files into excel. Each file has a header row and data. When the macro imports these files, I want it to only use one header row instead of what it is doing now. Is this even possible with variable file names? Here is a copy of the code I am using:

    Please Login or Register  to view this content.
    Please find attached example workbook and source files. Any assistance in this matter is greatly appreciated....Regards... Delta
    Attached Files Attached Files
    Last edited by Delta; 05-04-2012 at 02:48 AM. Reason: Wrong File

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Import multiple .TXT/.TAB files only using one header row

    Add a Boolean dim at the top:
    Please Login or Register  to view this content.

    Then change this:
    Please Login or Register  to view this content.

    ...to this:
    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    05-01-2012
    Location
    Texas
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Import multiple .TXT/.TAB files only using one header row

    Hello,

    Thanks for the quick reply. I have made the adjustments, saved, closed, and reopened.. The macro now hangs up here:

    Please Login or Register  to view this content.
    with a "Run-time error 1004 Application-defined or object-defined error"

    The Dim section now looks like this:

    Please Login or Register  to view this content.
    and the full code looks like this:

    Please Login or Register  to view this content.
    Thanks again for you knowledge and assistance.....Regards..... Delta

  4. #4
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Import multiple .TXT/.TAB files only using one header row

    hi Delta, try to change your original code as follows:

    Please Login or Register  to view this content.
    to

    Please Login or Register  to view this content.

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Import multiple .TXT/.TAB files only using one header row

    I had thought that trick might work to convert the Boolean TRUE into 1 to offset 1, I tested this and it works now:
    Please Login or Register  to view this content.

    Basically, the first time through the copy command Titles=False so it won't offset, thus including the title row. After that, it's always TRUE so it will always offset 1 row, skipping the titles.

  6. #6
    Registered User
    Join Date
    05-01-2012
    Location
    Texas
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Import multiple .TXT/.TAB files only using one header row

    Excellent.....The data is imported under one header... Exactly what I was looking for... Thank you so much JBeaucaire...watersev, your solution works as well but no headers are retained in the import. I probably was not clear as to what I was looking for... Your efforts are greatly appreciated... I was wondering if you guys could look at another post involving this same code and importing all data fields as text data format instead of the excel default of general data format, but I do not know how to link it here....Thanks again for sharing your knowledge, time, and effort.....Regards.... Delta

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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