PC Review


Reply
Thread Tools Rate Thread

Copy and paste in all closed files in a folder

 
 
b1llt
Guest
Posts: n/a
 
      15th Oct 2009
I would like to perform a copy & paste of the range A1:F50 within multiple
files in a folder (that are closed) just by running some code in a separate
file. The copy & paste would need to occur within each file --meaning that
it may be different data for each file depending what is in it's own range
A1:F50. The copied data would need to be inserted into row 1 --trying to get
the new data inserted above the existing data. Also, I'd like to have the
date change within cell C5 to a value entered by the user in the file that
the macro resides in.
Please let me know if this isn't clear as I may have rambled.
Thanks,
Bill
 
Reply With Quote
 
 
 
 
Patrick Molloy
Guest
Posts: n/a
 
      16th Oct 2009
its not 100% clear to me. Are you copying the data from sheet1 in each
workbook. so you copy sheet1 ! A1:F50 then just insert into the same place ie
replicating the
data?

the code to copy is

With Range("A1:F50")
.Copy
.Insert xlShiftDown
End With


to scroll through a folder, you can simply use the DIR() function...

Dim sFile As String
Const sFOLDER As String = "H:\excel\test\"
sFile = Dir(sFOLDER & "*.xls")
Do While sFile <> ""
MsgBox sFile
sFile = Dir()
Loop

so, putting this together:

Option Explicit
Sub Main()
Dim wb As Workbook
Dim sFile As String
Const sFOLDER As String = "H:\excel\test\"
sFile = Dir(sFOLDER & "*.xls")
Do While sFile <> ""
Set wb = Workbooks.Open(sFOLDER & sFile)
With wb.ActiveSheet.Range("A1:F50")
.Copy
.Insert xlShiftDown
Application.CutCopyMode = False
End With
wb.Close False ' CHANGE TO TRUE TO SAVE FILE
Set wb = Nothing
sFile = Dir()
Loop
End Sub








"b1llt" wrote:

> I would like to perform a copy & paste of the range A1:F50 within multiple
> files in a folder (that are closed) just by running some code in a separate
> file. The copy & paste would need to occur within each file --meaning that
> it may be different data for each file depending what is in it's own range
> A1:F50. The copied data would need to be inserted into row 1 --trying to get
> the new data inserted above the existing data. Also, I'd like to have the
> date change within cell C5 to a value entered by the user in the file that
> the macro resides in.
> Please let me know if this isn't clear as I may have rambled.
> Thanks,
> Bill

 
Reply With Quote
 
b1llt
Guest
Posts: n/a
 
      16th Oct 2009
Yes, 'sheet1' is actually labled '2009'. This does do what I wanted it to
but, what happens when we add in another sheet labled 2010 how do I
distinguish between sheets so it only happens on the most current?
Thanks again,
Bill

"Patrick Molloy" wrote:

> its not 100% clear to me. Are you copying the data from sheet1 in each
> workbook. so you copy sheet1 ! A1:F50 then just insert into the same place ie
> replicating the
> data?
>
> the code to copy is
>
> With Range("A1:F50")
> .Copy
> .Insert xlShiftDown
> End With
>
>
> to scroll through a folder, you can simply use the DIR() function...
>
> Dim sFile As String
> Const sFOLDER As String = "H:\excel\test\"
> sFile = Dir(sFOLDER & "*.xls")
> Do While sFile <> ""
> MsgBox sFile
> sFile = Dir()
> Loop
>
> so, putting this together:
>
> Option Explicit
> Sub Main()
> Dim wb As Workbook
> Dim sFile As String
> Const sFOLDER As String = "H:\excel\test\"
> sFile = Dir(sFOLDER & "*.xls")
> Do While sFile <> ""
> Set wb = Workbooks.Open(sFOLDER & sFile)
> With wb.ActiveSheet.Range("A1:F50")
> .Copy
> .Insert xlShiftDown
> Application.CutCopyMode = False
> End With
> wb.Close False ' CHANGE TO TRUE TO SAVE FILE
> Set wb = Nothing
> sFile = Dir()
> Loop
> End Sub
>
>
>
>
>
>
>
>
> "b1llt" wrote:
>
> > I would like to perform a copy & paste of the range A1:F50 within multiple
> > files in a folder (that are closed) just by running some code in a separate
> > file. The copy & paste would need to occur within each file --meaning that
> > it may be different data for each file depending what is in it's own range
> > A1:F50. The copied data would need to be inserted into row 1 --trying to get
> > the new data inserted above the existing data. Also, I'd like to have the
> > date change within cell C5 to a value entered by the user in the file that
> > the macro resides in.
> > Please let me know if this isn't clear as I may have rambled.
> > Thanks,
> > Bill

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot cut/copy/paste files from one folder to another-WiNXP SP3 Abhineet Windows XP General 1 27th Sep 2009 01:15 PM
Copy from closed excel file and paste to master file then loop for same siles Steve B Microsoft Excel Programming 2 6th Mar 2007 06:36 AM
Compare name and copy from closed .csv files Mikke Microsoft Excel Worksheet Functions 0 12th May 2006 11:49 PM
How do I reopen a closed personal files folder? =?Utf-8?B?bWlzc2Zsbw==?= Microsoft Outlook Discussion 1 18th Nov 2004 07:40 PM
edit copy, edit paste and draging files from folder to folder won't work? Neal Windows XP Help 0 17th Oct 2004 04:31 PM


Features
 

Advertising
 

Newsgroups
 


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