+ Reply to Thread
Results 1 to 8 of 8

Macro to open multiple text files and perform operations in each one. Then copy results.

  1. #1
    Registered User
    Join Date
    09-02-2014
    Location
    Bogotá, Colombia
    MS-Off Ver
    2010
    Posts
    6

    Macro to open multiple text files and perform operations in each one. Then copy results.

    Hello, this is the situation

    I´ve a folder with several text files, listed from 1 to 30. What i want is to open each file and sum all the values in the second column, then copy the result to a open excel file, the following code can do that only for one file, i think i have to implement a cycle, unfortunately i do not know how.

    Note that "(1-30).txt" are all the files

    Please Login or Register  to view this content.
    I hope someone can help, what i´ve done so far is changing the index of the file, but i know that repetitive task can be replaced esaily.

    Thanks in advance

    Greetings
    Last edited by JBeaucaire; 09-02-2014 at 12:15 PM. Reason: Added missing CODE tags. Please read and follow the Forum Rules, link above in the menu bar. Thanks.

  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: Macro to open multiple text files and perform operations in each one. Then copy result

    this macro would be installed INTO your destination workbook and will paste the results into a sheet called OUTPUT.
    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 09-02-2014 at 01:44 PM. Reason: Code correction
    _________________
    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
    09-02-2014
    Location
    Bogotá, Colombia
    MS-Off Ver
    2010
    Posts
    6

    Re: Macro to open multiple text files and perform operations in each one. Then copy result

    Thanks in advance sir, i´m getting an error
    "Run-Time error 91
    Object Variable or With Block not established"
    I click debbug and i get this "wsOUTPUT = ThisWorkbook.Sheets("Output") 'the sheet in THIS workbook to copy result to" highlitghed
    Maybe i have to change the name of the sheet?

    Thank you so much

    Greetings

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

    Re: Macro to open multiple text files and perform operations in each one. Then copy result

    Code correction above. Sorry.

  5. #5
    Registered User
    Join Date
    09-02-2014
    Location
    Bogotá, Colombia
    MS-Off Ver
    2010
    Posts
    6

    Re: Macro to open multiple text files and perform operations in each one. Then copy result

    Now is running Awesome, only one problem left it´ s pasting the formula and not the values, so i´m gettin

    REF#
    REF#
    REF#

    I´m not sure where should i put "Selection.PasteSpecial..."

    Thanks againa

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

    Re: Macro to open multiple text files and perform operations in each one. Then copy result

    Code corrected above... again.

  7. #7
    Registered User
    Join Date
    09-02-2014
    Location
    Bogotá, Colombia
    MS-Off Ver
    2010
    Posts
    6

    Re: Macro to open multiple text files and perform operations in each one. Then copy result

    Working Perfect!!

    Thank you so much

    Regards

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

    Re: Macro to open multiple text files and perform operations in each one. Then copy result

    As it appears you've reached a conclusion, I've marked this thread SOLVED for you.
    FYI, this is done through the Thread Tools located above the first post in this thread. Thanks.

+ 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. Macro to open a web page, perform a search and PDF the results
    By glide2131 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-26-2013, 06:16 PM
  2. macro to open multiple text files
    By ccloak in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-09-2013, 02:49 PM
  3. Replies: 13
    Last Post: 11-29-2012, 08:25 PM
  4. Replies: 6
    Last Post: 07-06-2012, 03:42 PM
  5. [SOLVED] Need to perform the same macro to multiple xls files in VB2005 Exp
    By Jhcorsair in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-29-2005, 11:00 PM

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