How do you optimize the process of gathering data; getting away from .Select

pawest

Board Regular
Joined
Jun 27, 2011
Messages
105
Hi VBA people,
I know that many advanced VBA users advocate getting away from using selects. It seems there are many work arounds. However, I have a project where a .select might be best. I would like to get the user community's feedback on how optimize and improve this process:

Code:
' Copy the file's data
Workbooks.Open fileName:=fileSpec 'here I reference the fileSpec variable which calls a csv file's location
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
        
' Import the data 
Windows("DataFile.xlsm").Activate
Sheets("Data").Select 
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                 :=False, Transpose:=False

Thanks!
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Perhaps

Code:
ActiveSheet.UsedRange.Copy
        
' Import the data
Workbooks("DataFile.xlsm").Sheets("Data").Range("A1").PasteSpecial Paste:=xlPasteValues
 
Upvote 0
VoG,
Thanks for your feedback. To provide more background on this project, I have one main data analysis file and I pull about 10 tabs of information from 10 different csv files. Would you still recommend the ActiveSheet.UsedRange.Copy? Sounds like I should just do a workbooks.open, then activate the file, then do the ActiveSheet.UsedRange.Copy?
 
Upvote 0
If you open a csv file then that will become the active workbook and the sheet that you want to copy from will already be the active sheet.
 
Upvote 0

Forum statistics

Threads
1,214,951
Messages
6,122,449
Members
449,083
Latest member
Ava19

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top