Right now, I’m creating a new workbook with 12 column names all in row 1 and every time I run my macro to test it, the workbook has a different name (Book1, Book2,….)
I want to get specific columns from a CLOSED workbook and paste them to different columns in this new workbook. I do NOT want to use the GetValuesFromAClosedWorkbook because in my macro, the user is picking the file (“Y:…\Test.xls”).
I have the following code which works, but is not as automated as I would like it to be because I will not know the name of the workbook…whether if it’s Book1, Book2, and so on…AND because it’s opening the file, which I don’t want it to do.
Workbooks.Open Filename:="Y:\......\Test.xls"
Range("D3").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Windows("Book1").Activate
ActiveWorkbook.ActiveSheet.Range("B2").PasteSpecial Paste:=xlValues
Is it possible that once the user picks the file, I can pick certain columns and paste them to this new workbook?
Any help will be appreciated!
Thank you!
When you open a workbook you can do this:
Or when you add a new workbook:
You can then use the reference
wb:Where
wbis the file you opened andwb2is the newly-added workbook.Using a “helper” sub to perform the copying:
If you want to copy both values and formats:
Usage: