Hi Izandol,
I'm back again, the code worked pretty well untill I realised It loads in files in a random order instead of the 1->x order ( now it is 1, 12 ,14, 3 ,5 ,... for example)
\. How can I force the sequence of the files I take my collumns of the way it should be so that first col comes from S01, 2nd from S02, etc...
Thanks already!
Here you can find the code:
Sub ImportDRIFTPCB()
'
' ImportDRIFTPCB Macro
'
'
Const csPATH As String = "C:\Users\allaer81\Documents\DataToAnalyze\"
Dim wb As Workbook
Dim lCounter As Long
Dim sFile As String
Application.ScreenUpdating = False
sFile = Dir(csPATH & "DRIFTPCB*.CSV")
Do While sFile <> ""
lCounter = lCounter + 1
Set wb = Workbooks.Open(Filename:=csPATH & sFile)
If lCounter = 1 Then
wb.Sheets(1).Columns("A:B").Copy
ThisWorkbook.ActiveSheet.Range("A1").PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Else
wb.Sheets(1).Columns("B:B").Copy Destination:=ThisWorkbook.ActiveSheet.Cells(1, lCounter + 1)
End If
wb.Close False
sFile = Dir()
Loop
Cells.NumberFormat = "0.00"
Range("B2").Value = "DRIFTPCBS01"
Range("B2").AutoFill Destination:=Range("B2").Resize(, lCounter), Type:=xlFillDefault
Cells(2, lCounter + 2).Resize(, 3).Value = Array("Average", "STDEV", "%")
Cells(4, lCounter + 2).FormulaR1C1 = "=AVERAGE(RC2:RC[-1])"
Cells(4, lCounter + 3).FormulaR1C1 = "=STDEV(RC2:RC[-2])"
With Cells(4, lCounter + 4)
.FormulaR1C1 = "=RC[-1]/RC[-2]"
.NumberFormat = "0.0000%"
End With
Cells(4, lCounter + 2).Resize(, 3).AutoFill Destination:=Cells(4, lCounter + 2).Resize(200, 3)
Cells.EntireColumn.AutoFit
Application.ScreenUpdating = True
End Sub
Bookmarks