It is always fun and instructive to figure out one of snb's codes.
I tried to make this verbose and simple enough that eve a Czech, (home of the Tatra,) Statistical Analyst can figure it out
If it errors, please note the error statement and number for us.
Place this code in a standard Module, Edit the FolderPath Constant to fit. After you see the Message "IT Works! Stopping Sub" Then code your next formula and run it again. The Message shows after only10 files have been successfully processed. When the code is complete and runs all the way to the message, remove the "For Testing Only" section at the bottom.
To run the Sub, make sure an empty sheet is visible in Excel, then in the VBA, put the mouse cursor anywhere in the sub and press F5. BTW, Press F8 to step (run) through the code one line at a time. If you do that, you can hover the mouse over a variable to see its Value at that time.
Option Explicit Sub SamT_snb() Dim Filename As String Dim NameLength As Long Dim FileNameArray As Variant 'sn Dim FileLinesArray As Variant 'sp Dim Formula1LinesArray As Variant Dim Formula1Result As Double 'y 'Repeat these two lies for each Formula. Edit the numbers to suit Dim Formula2LinesArray As Variant Dim Formula2Result As Double Dim Fn As Long 'Fn = Index number for FileNameArray 'jj Dim Fl As Long 'Fl = FileLinesArray Index number 'j Const FolderPath As String = "The Path to your folder must go here\" 'include ending \ '''' Put all the file names in the path in Array FileNameArray = Filter(Split(CreateObject("wscript.shell").exec(FolderPath & "*.csv /b /s").stdout.readall, vbCrLf), ".") '''' Open one file at a time With CreateObject("scripting.filesystemobject") For Fn = 0 To UBound(FileNameArray) ''''Put all lines from one file in Arrays FileLinesArray = Split(.opentextfile(FileNameArray(Fn)).readall, vbCrLf) Formula1LinesArray = FileLinesArray Formula2LinesArray = FileLinesArray 'Initializ Formula1Result = 0 Formula2Result = 0 ''''Calcuate first result for one file For Fl = 0 To UBound(FileLinesArray) '''' Calculate first formula 'Replace file line with Log of 6th value. Split(BlahBlah)(5) Formula1LinesArray(Fl) = Log(Split(Formula1LinesArray(Fl), ",")(5)) 'After the first line If Fl > 0 Then Formula1Result = Formula1Result + Formula1Result + _ (Formula1LinesArray(Fl) - Formula1LinesArray(Fl - 1) ^ 2) * 100 '''' Calculate second Formula here 'Replace file line with first part of formula. Think carefully 'Formula2LinesArray (Fl) = Your formula here Next Fl '''' Put results in sheet 'Get FileName NameLength = Len(FileNameArray(Fn)) - InStrRev(FileNameArray, "\") Filename = Right(FileNameArray(Fn), NameLength) 'Place result With ActiveSheet.Rows(Fn + 1) .Columns(2) = Formula1Result 'Column B .Columns(3) = Formula2Result .Columns(4) = Filename End With 'Initialize Arrays FileLinesArray = "" Formula1LinesArray = FileLinesArray Formula2LinesArray = FileLinesArray ''''' For testing only If Fn >= 100 Then MsgBox "IT Works! Stopping Sub" Exit Sub End If ''''End Test Next Fn 'Work on next File End With End Sub





,) Statistical Analyst can figure it out 
Reply With Quote