Hi all, I'm new here and I have a question and I hope you guys could help me out.
In the code on the on the bottom of this message I'd like to optimize, for example, Somethimes I have 10 PCB-flies (PCBS01-PCBS10), somethimes I get more, for example (PCBS01-PCBS27), is there a way to easily adjust everything by using loops or something? Also every collumn I copy from one file must be placed on the adjacent collumn and at the end I want as you can see have an extra collumn with average, and also one with the stdev. If more info required or if this impossible, please let me know 
Thanks and greetings from Belgium!
Sub ImportPCB()
'
' ImportPCB Macro
'
'
ChDir "C:\Users\allaer81\Documents\Dimitri04Feb2014"
Workbooks.Open Filename:= _
"C:\Users\allaer81\Documents\Dimitri04Feb2014\PCBS01.CSV"
Columns("A:B").Select
Selection.Copy
Windows("Dimitri04Feb2014Analysis.xlsx").Activate
Columns("A:A").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Windows("PCBS01.CSV").Activate
Application.CutCopyMode = False
ActiveWindow.Close
Workbooks.Open Filename:= _
"C:\Users\allaer81\Documents\Dimitri04Feb2014\PCBS02.CSV"
Columns("B:B").Select
Selection.Copy
Windows("Dimitri04Feb2014Analysis.xlsx").Activate
Columns("C:C").Select
ActiveSheet.Paste
Windows("PCBS02.CSV").Activate
Application.CutCopyMode = False
ActiveWindow.Close
Workbooks.Open Filename:= _
"C:\Users\allaer81\Documents\Dimitri04Feb2014\PCBS03.CSV"
Columns("B:B").Select
Selection.Copy
Windows("Dimitri04Feb2014Analysis.xlsx").Activate
Columns("D:D").Select
ActiveSheet.Paste
Windows("PCBS03.CSV").Activate
Application.CutCopyMode = False
ActiveWindow.Close
Workbooks.Open Filename:= _
"C:\Users\allaer81\Documents\Dimitri04Feb2014\PCBS04.CSV"
Columns("B:B").Select
Selection.Copy
Windows("Dimitri04Feb2014Analysis.xlsx").Activate
Columns("E:E").Select
ActiveSheet.Paste
Windows("PCBS04.CSV").Activate
Application.CutCopyMode = False
ActiveWindow.Close
Workbooks.Open Filename:= _
"C:\Users\allaer81\Documents\Dimitri04Feb2014\PCBS05.CSV"
Columns("B:B").Select
Selection.Copy
Windows("Dimitri04Feb2014Analysis.xlsx").Activate
Columns("F:F").Select
ActiveSheet.Paste
Windows("PCBS05.CSV").Activate
Application.CutCopyMode = False
ActiveWindow.Close
Workbooks.Open Filename:= _
"C:\Users\allaer81\Documents\Dimitri04Feb2014\PCBS06.CSV"
Columns("B:B").Select
Selection.Copy
Windows("Dimitri04Feb2014Analysis.xlsx").Activate
Columns("G:G").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Windows("PCBS06.CSV").Activate
Application.CutCopyMode = False
ActiveWindow.Close
Workbooks.Open Filename:= _
"C:\Users\allaer81\Documents\Dimitri04Feb2014\PCBS07.CSV"
Columns("B:B").Select
Selection.Copy
Windows("Dimitri04Feb2014Analysis.xlsx").Activate
Columns("H:H").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Windows("PCBS07.CSV").Activate
Application.CutCopyMode = False
ActiveWindow.Close
Workbooks.Open Filename:= _
"C:\Users\allaer81\Documents\Dimitri04Feb2014\PCBS08.CSV"
Columns("B:B").Select
Selection.Copy
Windows("Dimitri04Feb2014Analysis.xlsx").Activate
Columns("I:I").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Windows("PCBS08.CSV").Activate
Application.CutCopyMode = False
ActiveWindow.Close
Workbooks.Open Filename:= _
"C:\Users\allaer81\Documents\Dimitri04Feb2014\PCBS09.CSV"
Columns("B:B").Select
Selection.Copy
Windows("Dimitri04Feb2014Analysis.xlsx").Activate
Columns("J:J").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Windows("PCBS09.CSV").Activate
Application.CutCopyMode = False
ActiveWindow.Close
Workbooks.Open Filename:= _
"C:\Users\allaer81\Documents\Dimitri04Feb2014\PCBS10.CSV"
Columns("B:B").Select
Selection.Copy
Windows("Dimitri04Feb2014Analysis.xlsx").Activate
Columns("K:K").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Windows("PCBS10.CSV").Activate
Application.CutCopyMode = False
ActiveWindow.Close
Workbooks.Open Filename:= _
"C:\Users\allaer81\Documents\Dimitri04Feb2014\PCBS11.CSV"
Columns("B:B").Select
Selection.Copy
Windows("Dimitri04Feb2014Analysis.xlsx").Activate
Columns("L:L").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Windows("PCBS11.CSV").Activate
Application.CutCopyMode = False
ActiveWindow.Close
Cells.Select
Selection.NumberFormat = "0.00"
Range("B2").Select
ActiveCell.FormulaR1C1 = "PCBS01"
Range("B2").Select
Selection.AutoFill Destination:=Range("B2:L2"), Type:=xlFillDefault
Range("B2:L2").Select
Range("M2").Select
ActiveCell.FormulaR1C1 = "Average"
Range("N2").Select
ActiveCell.FormulaR1C1 = "STDEV"
Range("O2").Select
ActiveCell.FormulaR1C1 = "%"
Range("M4").Select
ActiveCell.FormulaR1C1 = "=AVERAGE(RC[-11]:RC[-1])"
Range("N4").Select
ActiveCell.FormulaR1C1 = "=STDEV(RC[-12]:RC[-2])"
Range("O4").Select
ActiveCell.FormulaR1C1 = "=RC[-1]/RC[-2]"
Range("O4").Select
Selection.Style = "Percent"
Selection.NumberFormat = "0.0%"
Selection.NumberFormat = "0.00%"
Selection.NumberFormat = "0.000%"
Selection.NumberFormat = "0.0000%"
Range("M4").Select
Selection.AutoFill Destination:=Range("M4:M204")
Range("M4:M204").Select
Range("N4").Select
Selection.AutoFill Destination:=Range("N4:N204")
Range("N4:N204").Select
Range("O4").Select
Selection.AutoFill Destination:=Range("O4:O204")
Range("O4:O204").Select
Cells.Select
Cells.EntireColumn.AutoFit
End Sub
Bookmarks