code has too much "select"

Chas17

Well-known Member
Joined
Oct 16, 2002
Messages
657
I have a csv file created from an enterprise program (P6).
If I "query" the csv file from an excel workbook, the data will not come over due to the way the csv file is. It has hard returns and the Program (P6) input certain text and calculations, so when either "queried" or "imported" (delimited) the csv file data does not come in at all or is offset to corrupt the data per column.

The code I have copies the range of used data and places it in the sheet I need it in.

Can this code be cleaned up so it does not "select" as much, or even get the data without opening the WB?

If I copy the sheet I would need to rename the "code" name of the imported sheet as other sheets use the code name in subroutines.

Code:
Sub ChasImpDatHrs()

Dim StartSheet As Worksheet

Set StartSheet = ActiveSheet

Application.ScreenUpdating = False
wksMHrsData.Cells.ClearContents

Workbooks.Open Filename:= _
    "H:\SOD\Cycle_Week_BC\Role_Resources\Data\Hrs_T0_T14_chas.csv"
    
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Selection.Copy
    Windows("Role Limits5b.xls").Activate
    wksMHrsData.Visible = xlSheetVisible
    wksMHrsData.Select
    wksMHrsData.Range("a1").Select
    ActiveSheet.Paste
    Range("A1").Select
    Application.CutCopyMode = False
    Windows("Hrs_T0_T14_chas.csv").Close
    wksMHrsData.Visible = xlSheetVeryHidden

StartSheet.Select
End Sub

Would it be worth writing code to save the csv file as an xls and then delete a column not needed (causing the problem)?
Thanks, Chas
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
try activesheet.usedrange.copy


wksMHrsData.Range("a1").Select
ActiveSheet.Paste
wksMHrsData.Range("a1")paste



</pre>
 
Upvote 0
Thanks

modified to:
wksMHrsData.Range("a1").PasteSpecial xlPasteAll

paste not a keyword here

Thank you.
 
Upvote 0

Forum statistics

Threads
1,214,808
Messages
6,121,686
Members
449,048
Latest member
81jamesacct

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