Copy/Paste between two worksheets

rollingzep

Board Regular
Joined
Nov 18, 2013
Messages
214
Office Version
  1. 365
Platform
  1. Windows
Hi,

I import a text file to my FX Worksheet in my Workbook, WBFX.

I then insert a row at the very top of my FX Worksheet. I then copy the header from another worksheet, EX which is the same Workbook.

I need to paste it to the top row of my FX Worksheet.

Currently, I am doing this manually. I need help with coding to insert a row, copy header from the second sheet, select the top row of the first sheet and paste the header row.

How to do this?

Also, the weekly text file I import is dated. While the name is same, the date changes every week. (example - xxxx_FX_04182002).
I have currently hardcoded the text file.

Can I automate the date part?

Thanks
 

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.
Currently, I am doing this manually. I need help with coding to insert a row, copy header from the second sheet, select the top row of the first sheet and paste the header row.
You should be able to get most of the code you need for this using the Macro Recorder.
Simply turn on your Macro Recorder, and record yourself performing these steps manually, then stop the Macro Recorder.
Then go into the VB Editor and look at the code you just recorded. You should be able to copy/paste this into your VBA procedure, and it should do what you want.
 
Upvote 0
You should be able to get most of the code you need for this using the Macro Recorder.
Simply turn on your Macro Recorder, and record yourself performing these steps manually, then stop the Macro Recorder.
Then go into the VB Editor and look at the code you just recorded. You should be able to copy/paste this into your VBA procedure, and it should do what you want.
I was able to use the macro recorder and modify the code to suit my req.

But I need help with the below.
The weekly text file I import is dated. While the name is same, the date changes every week. (example - xxxx_FX_04182002).
I have currently hardcoded the text file.
Can I automate the date part?
 
Upvote 0
I was able to use the macro recorder and modify the code to suit my req.

But I need help with the below.
The weekly text file I import is dated. While the name is same, the date changes every week. (example - xxxx_FX_04182002).
I have currently hardcoded the text file.
Can I automate the date part?
If you post the VBA code that you have with that hard-coded file name, we can probably help you modify it to do what you need.
Please be sure to post your code as described here: How to Post Your VBA Code
 
Upvote 0
It's simple

Code:
strfilename = "P:\FX_Reports\xxxx_FX_04182002.txt"
strDelimiter = "|"

intTextFile = FreeFile
Open strFileName For Input As intTextFile
strTextFileContent = Input(LOF(intTextFile), intTextFile)

Close intTextFile
 
Upvote 0
OK, what is the logic for the date used in the filename that you will be looking for?
Will the date always be the MONDAY of that week?

And when will you be running this code, compared to the date in the filename?
Will you always be running it on Monday (same day) or Tuesday (next day)?
Or could you be running it on any date of that week?
 
Upvote 0
I apologize for not providing details. I am new to this team
It is an quarterly file. The last was xxxx_FX_20220331. txt
We run it the next day.
 
Upvote 0
If you want to return the file with date in the name from the previous day, you can use this to set the file name:
VBA Code:
strfilename = "P:\FX_Reports\xxxx_FX_" & Format(Date - 1, "mmddyyyy") & ".txt"
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,425
Members
448,961
Latest member
nzskater

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