Results 1 to 8 of 8

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

Threaded View

  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

    Sub Sample()
    
            Workbooks.OpenText Filename:="C:\Users\Jorge\Desktop\Resultados\4.txt", _
            Origin:=xlMSDOS, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
            xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _
            Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), _
            Array(2, 1)), DecimalSeparator:=".", ThousandsSeparator:=",", _
            TrailingMinusNumbers:=True
            Range("C2").Select
            ActiveCell.FormulaR1C1 = "=SUM(RC[-1]:R[5719]C[-1])"
            Range("C3").Select
            ActiveWindow.SmallScroll Down:=-18
            Range("C2").Select
            Selection.Copy
            Windows("Libro1.xlsm").Activate
            ActiveWindow.SmallScroll Down:=-21
            Range("A4").Select
            Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
            Windows("4.txt").Activate
            Application.CutCopyMode = False
            Selection.ClearContents
            ActiveWindow.Close
           
    End Sub
    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.

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. 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