Add Reference "Scripting.FileSystemObject" (Microsoft Scripting Runtime) ' For manipulating files, directories
SubData Grooming section ()"'data collation to new sheet'' DimFso as NewFileSystemObjectDimFolder asfolderDimFile asfileDimStrext as String DimWkb asWorkbook Strext="xlsx" 'find a specific suffix name file Setfolder =FSO. GetFolder (Thisworkbook.path) for eachFileinchfolder. Files Fileext=FSO. Getextensionname (file)IfFileext = Strext Then SetWKB =workbooks.open (file)'original data form moved to firstSheets ("Sheet1"). Move Before:=sheets (1) IfWkb. Sheets.count <2 ThenWKB. Sheets.add after:=WKB. Sheets ("Sheet1") End If DimSheet1 asWorksheetDimSheet2 asWorksheetSetSheet1 = wkb. Sheets (1) SetSheet2 = wkb. Sheets (2) DimDatacount as LongDatacount=Sheet1. UsedRange.Rows.Count'gets the number of rows of data, adding DTSheet2. Range ("A1"). Value ="DT (s)"Sheet2. Range ("a2:a"& Datacount). Value =0.0175SubName="_euler" If(InStr(file. Name, SubName) >0) Then 'Eligible FilesWkb. Sheets (2). Name ="Euler"Sheet1. Columns ("q:s"). Copy Sheet2. Range ("B1"). PasteSpecial paste:=xlpastevalues, Operation:=xlnone, skipblanks:=False, transpose:=False ElseWKB. Sheets (2). Name ="Sensor" 'Gyroscope DataSheet1. Columns ("Ac:ae"). Copy Sheet2. Range ("B1"). PasteSpecial paste:=xlpastevalues, Operation:=xlnone, skipblanks:=False, transpose:=False 'magnetometer DataSheet1. Columns ("Ai:ak"). Copy Sheet2. Range ("E1"). PasteSpecial paste:=xlpastevalues, Operation:=xlnone, skipblanks:=False, transpose:=False 'Accelerometer DataSheet1. Columns ("Af:ah"). Copy Sheet2. Range ("H1"). PasteSpecial paste:=xlpastevalues, Operation:=xlnone, skipblanks:=False, transpose:=False 'here the function parentheses will be an error!!! Calculate displacement Part Sheet2End If 'Close ExcelWKB. Save WKB. CloseEnd If Next End Sub SubCalculate Displacement Section (sheet asWorksheet)DimDatacount as LongDatacount=sheet. UsedRange.Rows.Count'Raw Data IntegrationSheet. Range ("K1"). Value ="Ax (M/S/S)"sheet. Range ("k2:k"& Datacount). FORMULAR1C1 ="=rc8*9.81"sheet. Range ("L1"). Value ="Vx (M/s)"sheet. Range ("L2"). Value =0sheet. Range ("l3:l"& Datacount). FORMULAR1C1 ="=r[-1]c+rc[-1]*rc1"sheet. Range ("M1"). Value ="Sx (m)"sheet. Range ("M2"). Value =0sheet. Range ("m3:m"& Datacount). FORMULAR1C1 ="=r[-1]c+rc[-1]*rc1" 'Subtract noise integralSheet. Range ("K1"). Value ="ax-ave100 (M/S/S)"sheet. Range ("k2:k"& Datacount). FORMULAR1C1 ="= (Rc8-average (R2C8:R101C8)) *9.81"sheet. Range ("L1"). Value ="vx-ave100 (M/s)"sheet. Range ("L2"). Value =0sheet. Range ("l3:l"& Datacount). FORMULAR1C1 ="=r[-1]c+rc[-1]*rc1"sheet. Range ("M1"). Value ="sx-ave100 (m)"sheet. Range ("M2"). Value =0sheet. Range ("m3:m"& Datacount). FORMULAR1C1 ="=r[-1]c+rc[-1]*rc1" End Sub
VBA actions on multiple files in Excel