I am trying to create script to a macro that will copy certain columns in a large data-set in excel and create a new excel workbook of those columns in respective order -- Only the values to be copied over and not the formulas. This is what I have so far after using the Macro recorder:
Sub Compfinder()
'
' Compfinder Macro
'
'
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 3
ActiveWindow.ScrollColumn = 4
ActiveWindow.ScrollColumn = 5
ActiveWindow.ScrollColumn = 6
ActiveWindow.ScrollColumn = 7
ActiveWindow.ScrollColumn = 8
ActiveWindow.ScrollColumn = 9
ActiveWindow.ScrollColumn = 10
Columns("Q:Q").Select
Selection.Copy
Workbooks.Add
Columns("A:A").Select
ActiveSheet.Paste
Range("A1").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "Geo Location"
Windows("CompFinder Tool_Protected_final_11.25.13.xlsm").Activate
Columns("K:K").Select
Selection.Copy
Windows("Book1").Activate
Columns("B:B").Select
Selection.PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone _
, SkipBlanks:=False, transpose:=False
Windows("CompFinder Tool_Protected_final_11.25.13.xlsm").Activate
Windows("Book1").Activate
Windows("CompFinder Tool_Protected_final_11.25.13.xlsm").Activate
Columns("L:L").Select
Application.CutCopyMode = False
Selection.Copy
Windows("Book1").Activate
Columns("C:C").Select
Selection.PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone _
, SkipBlanks:=False, transpose:=False
Application.CutCopyMode = False
ActiveWorkbook.SaveAs Filename:= _
"C:\Users\raysharm\Documents\Compfinder columns.csv", FileFormat:=xlCSV, _
CreateBackup:=False
End Sub
When running the macro, I end up getting a bug error for Windows("Book1").Activate
, and I imagine I will for the other cut and pastes in the code.
Is there a way so that every time the macro is run, a brand new workbook is created with the respective desired columns to be copy and pasted? What should I put instead of "Book1"?
Thanks, Ray