Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Sam Sam is offline
external usenet poster
 
Posts: 699
Default VBA Macro to copy an column from one Excel file into another file

Hello,

I kept trying to get this to work, but my knowledge of VBA is insufficient
for this task.

I have 85 tab-delimited text files in folder c:\input\
I have one input Excel file - c:\input.xls
I need to

1. Open the first text input file

2. copy the third column of this file and paste it into the third column of
c:\input.xls

3. Allow c:\input.xls to recalculate the values in all other columns

4. Save the resulting file as a tab-delimited text file in folder
c:\output\ under the same file name as the name of the file from which we
copied the third column.
(i.e., if we the file that we opened in step 1 was c:\input\acmaininput.txt,
then in step 4 we want to create the file c:\output\acmaininput.txt)

5. Repeat steps 1-4 until we do this for all 85 files in c:\input folder.

I would be very grateful for any help with this. Thank you!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default VBA Macro to copy an column from one Excel file into another file

Check this previous post in Google http://tinyurl.com/9p7ya

--
HTH

Bob Phillips

"Sam" wrote in message
...
Hello,

I kept trying to get this to work, but my knowledge of VBA is insufficient
for this task.

I have 85 tab-delimited text files in folder c:\input\
I have one input Excel file - c:\input.xls
I need to

1. Open the first text input file

2. copy the third column of this file and paste it into the third column

of
c:\input.xls

3. Allow c:\input.xls to recalculate the values in all other columns

4. Save the resulting file as a tab-delimited text file in folder
c:\output\ under the same file name as the name of the file from which we
copied the third column.
(i.e., if we the file that we opened in step 1 was

c:\input\acmaininput.txt,
then in step 4 we want to create the file c:\output\acmaininput.txt)

5. Repeat steps 1-4 until we do this for all 85 files in c:\input folder.

I would be very grateful for any help with this. Thank you!



  #3   Report Post  
Posted to microsoft.public.excel.programming
Sam Sam is offline
external usenet poster
 
Posts: 699
Default VBA Macro to copy an column from one Excel file into another f

Check this previous post in Google http://tinyurl.com/9p7ya

Thank you. But does it make a difference that the files in that macro
are excel files and my files are text files? Also, I wanted to save the
files as tab-delimited text files...

Thank you
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default VBA Macro to copy an column from one Excel file into another f

Not, you just test for it

If oFile.Type = "Text Document" Then


--
HTH

Bob Phillips

"Sam" wrote in message
...
Check this previous post in Google http://tinyurl.com/9p7ya


Thank you. But does it make a difference that the files in that macro
are excel files and my files are text files? Also, I wanted to save the
files as tab-delimited text files...

Thank you



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default VBA Macro to copy an column from one Excel file into anotherf

To see how to save as a text file, record a macro and see how it looks.
The default txt file is tab delimited so it is easy. I find the
method shown (using Set oFSO =
CreateObject("Scripting.FileSystemObject") ) to be cumbersome for a
simple task like you asked. Look at the DIR function. You can specify
a *.txt filter (or more complex like a*.txt).

To get you started:

Sub ReadTextFiles()

Dim strFileName As String
Dim strInFilePath As String
Dim strOutFilePath As String
Dim strFilter As String

'for speed, don't show everything. Comment next line for testing
Application.ScreenUpdating = False

'open the master file here, possibly readonly for safety.
' maybe assign it to a workbook object

strInFilePath = "c:\input\"
strOutFilePath = "c:\Output\"
strFilter = "*.txt"
'paths and filter could be read from cells

strFileName = Dir(strInFilePath & strFilter) 'gets the first filename
Do While Len(strFileName) 0 'I like this better than < ""
'record macros to do these steps, paste here and adapt:
'open strFileName
'copy column c
'activate master file
'paste column c
'save as strFileName to strOutFilePath as text
'reopen master file (if necessary)
strFileName = Dir 'gets the next file, or "" if no more
Loop
Application.ScreenUpdating = True
End Sub

Try it and reply if you need more help.

Len


Sam wrote:
Check this previous post in Google http://tinyurl.com/9p7ya



Thank you. But does it make a difference that the files in that macro
are excel files and my files are text files? Also, I wanted to save the
files as tab-delimited text files...

Thank you

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to copy 2007 excel file formula results into a 2003 Excel file Nuria Alba de Luz Excel Discussion (Misc queries) 2 July 10th 09 01:48 PM
How do I copy a excel file into a InDesign file correctly? cfb Excel Discussion (Misc queries) 2 June 14th 07 10:08 PM
Saving a copy of excel file in macro but have it auto write pano Excel Worksheet Functions 4 March 27th 07 11:54 PM
Excel '00, 1st file has macros, how to stop macro in 2nd file? kaptandrews Excel Discussion (Misc queries) 0 May 24th 06 03:07 PM
How do I change *.CSV excel file to column seperated file? Pankaj Excel Discussion (Misc queries) 2 July 5th 05 07:35 PM


All times are GMT +1. The time now is 07:07 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"