Copy range to / from CSV file

  • Thread starter Thread starter blackbox via OfficeKB.com
  • Start date Start date
B

blackbox via OfficeKB.com

I receive a CSV file each morning and have to copy range E2:E22 and copy it
to a XLS sheet (calculator) range H2:H22 then copy I2:I22 form the XLS sheet
to a second CSV file range F2:F22.

I assume that this is probably not too difficult but not quite sure where to
begin, other than the macro would have to be in the XLS file.

Any help would be appreciated.
 
Start by recording a macro whilst perform those actions.
This will give you the basic code.

If the filenames remain constant, that will work.
If they change each day, check the help for GetOpenFileName and incorporate
it into your code.

NickHK
 
I tried to record a macro copying from the CSV and pasting to the xls but got
an error message

run-time error '1004':
Paste method of Worksheet class failed

This is the code generated

Sub import()
'
' import Macro
' Macro recorded 6/14/2007 by Administrator
'

'
Range("E2").Select
ActiveSheet.Paste
End Sub

I also tried a drag and drop without any luck
Start by recording a macro whilst perform those actions.
This will give you the basic code.

If the filenames remain constant, that will work.
If they change each day, check the help for GetOpenFileName and incorporate
it into your code.

NickHK
I receive a CSV file each morning and have to copy range E2:E22 and copy it
to a XLS sheet (calculator) range H2:H22 then copy I2:I22 form the XLS sheet
[quoted text clipped - 4 lines]
Any help would be appreciated.
 
You are opening the .csv in Excel ?
If not, then E2:E22 means nothing.

If you are opening in Excel, then the macro recorder will get the file name
and copy/paste actions.

NickHK

blackbox via OfficeKB.com said:
I tried to record a macro copying from the CSV and pasting to the xls but got
an error message

run-time error '1004':
Paste method of Worksheet class failed

This is the code generated

Sub import()
'
' import Macro
' Macro recorded 6/14/2007 by Administrator
'

'
Range("E2").Select
ActiveSheet.Paste
End Sub

I also tried a drag and drop without any luck
Start by recording a macro whilst perform those actions.
This will give you the basic code.

If the filenames remain constant, that will work.
If they change each day, check the help for GetOpenFileName and incorporate
it into your code.

NickHK
I receive a CSV file each morning and have to copy range E2:E22 and copy it
to a XLS sheet (calculator) range H2:H22 then copy I2:I22 form the XLS
sheet
[quoted text clipped - 4 lines]
Any help would be appreciated.
 
i recorder the macro in the xls, open the csv. copied, pasted to the xls

i had hoped it would recognize the different workbooks
You are opening the .csv in Excel ?
If not, then E2:E22 means nothing.

If you are opening in Excel, then the macro recorder will get the file name
and copy/paste actions.

NickHK
I tried to record a macro copying from the CSV and pasting to the xls but got
an error message
[quoted text clipped - 31 lines]
 
But do you open the csv IN Excel ?
If you open the .csv in another program before you copy, then Excel has no
way to know what you are doing.

Excel can open csv natively, in case you did not know.

NickHK

blackbox via OfficeKB.com said:
i recorder the macro in the xls, open the csv. copied, pasted to the xls

i had hoped it would recognize the different workbooks
You are opening the .csv in Excel ?
If not, then E2:E22 means nothing.

If you are opening in Excel, then the macro recorder will get the file name
and copy/paste actions.

NickHK
I tried to record a macro copying from the CSV and pasting to the xls but got
an error message
[quoted text clipped - 31 lines]
Any help would be appreciated.
 
i do open it in excel, however I have been opening it in a second excel
window so I can view them side by side.

is that the problem?
But do you open the csv IN Excel ?
If you open the .csv in another program before you copy, then Excel has no
way to know what you are doing.

Excel can open csv natively, in case you did not know.

NickHK
i recorder the macro in the xls, open the csv. copied, pasted to the xls
[quoted text clipped - 13 lines]
 
Do you mean a second instance of Excel ?
Look in the task manager and see how many Excel you have.

Also post the code that you have for the opening and copy/paste so far.

NickHK

blackbox via OfficeKB.com said:
i do open it in excel, however I have been opening it in a second excel
window so I can view them side by side.

is that the problem?
But do you open the csv IN Excel ?
If you open the .csv in another program before you copy, then Excel has no
way to know what you are doing.

Excel can open csv natively, in case you did not know.

NickHK
i recorder the macro in the xls, open the csv. copied, pasted to the xls
[quoted text clipped - 13 lines]
Any help would be appreciated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top