If file is saved as .xlsm then yes you must change this. If it is file with code we may use better syntax:
Sub ImportPCB()
'
' ImportPCB Macro
'
'
Const csPATH As String = "C:\Users\allaer81\Documents\Dimitri04Feb2014\"
' change this number as required
Const NUMBER_OF_FILES As Long = 11
Dim wb As Workbook
Dim n As Long
Application.ScreenUpdating = False
Set wb = Workbooks.Open(Filename:=csPATH & "PCBS01.CSV")
wb.Sheets(1).Columns("A:B").Copy
ThisWorkbook.ActiveSheet.Range("A1").PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
wb.Close False
For n = 2 To NUMBER_OF_FILES
Set wb = Workbooks.Open(Filename:=csPATH & "PCBS" & Format(n, "00") & ".CSV")
wb.Sheets(1).Columns("B:B").Copy Destination:=ThisWorkbook.ActiveSheet.Cells(1, n + 1)
wb.Close False
Next n
Cells.NumberFormat = "0.00"
Range("B2").Value = "PCBS01"
Range("B2").AutoFill Destination:=Range("B2:L2"), Type:=xlFillDefault
Cells(2, NUMBER_OF_FILES + 2).Resize(, 3).Value = Array("Average", "STDEV", "%")
Cells(4, NUMBER_OF_FILES + 2).FormulaR1C1 = "=AVERAGE(RC[-11]:RC[-1])"
Cells(4, NUMBER_OF_FILES + 3).FormulaR1C1 = "=STDEV(RC[-12]:RC[-2])"
With Cells(4, NUMBER_OF_FILES + 4)
.FormulaR1C1 = "=RC[-1]/RC[-2]"
.NumberFormat = "0.0000%"
End With
Cells(4, NUMBER_OF_FILES + 2).Resize(, 3).AutoFill Destination:=Cells(4, NUMBER_OF_FILES + 2).Resize(200, 3)
Cells.EntireColumn.AutoFit
Application.ScreenUpdating = True
End Sub
Bookmarks