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
Bookmarks