Forum Statistics
- Forum Members:
- Total Threads:
- Total Posts: 8
There are 1 users currently browsing forums.
|
 |

07-01-2009, 01:24 AM
|
|
Registered User
|
|
Join Date: 09 Mar 2008
Posts: 4
|
|
|
macro to copy specific data from many workbook to one workbook
Please Register to Remove these Ads
Dear All,
I have a excelFile(File Attached)
File contain following sheets
1 Form
2.File name
3.Purchase
4.Delayed Report
File name sheet contain location or Path where File is store
I need a macro to Do Following Action
On running code Open first (Purchase1.xls)
Find Delayed in Column F
If F1=Delayed than copy that Row
Paste entire row in Sheet Mention Delayed Report in Cell A2
Search Next Cell in F Column
if F2 not Equal to Delayed than leave
Search Next Cell in F Column
if F3 Equal to Delayed than Copy Entire Row
Paste entire row in Sheet Mention Delayed Report in Cell A3
Search Next Cell in F Column up to blank cell
If Cell number if F65536 than close Purchase1
Open Second File and Repate the proceess till end
Anyone help onthis
Thanks in Advance
ANVESH
|

07-01-2009, 02:49 AM
|
 |
Forum Guru
|
|
Join Date: 21 Mar 2008
Location: Bakersfield, CA
MS Office Version:2003 (can read 2007 files)
Posts: 9,470
|
|
|
Re: macro to copy specific data from many workbook to one workbook
Adjust your C2 formula so that the path includes the closing "\" and then put all your Purchase??.xls files into that folder.
Run this macro, it won't need FileName sheet, it will open every file in that folder with the correct name and pull in the data.
Code:
Option Explicit
Sub CollateReportFromFiles()
'JBeaucaire (6/30/2009)
'Open all .XLS in specific folder and import data (2007 compatible)
Dim strFileName As String, strPath As String
Dim wbkOld As Workbook, wbkNew As Workbook, ws As Worksheet
Dim NR As Long, LR As Long
Application.EnableEvents = False
Application.DisplayAlerts = False
'Setup and clear old report
Set wbkNew = ThisWorkbook
strPath = Sheets("FORM").Range("C2") 'Your path, don't forget the final \
strFileName = Dir(strPath & "Purchase*.xls")
Set ws = Sheets("Delayed Report")
ws.Activate
ws.Cells.Clear
'Collect data in new report
NR = 1
Do While Len(strFileName) > 0
Set wbkOld = Workbooks.Open(strPath & strFileName)
Range("A1:F1").AutoFilter
Range("A1:F1").AutoFilter Field:=6, Criteria1:="Delayed"
LR = Range("A" & Rows.Count).End(xlUp).Row
If LR > 1 Then
Range("A2:F" & LR).Copy
wbkNew.Activate
ws.Range("A" & NR).PasteSpecial xlPasteAll
End If
NR = ws.Range("A" & Rows.Count).End(xlUp).Row + 1
strFileName = Dir
wbkOld.Close False
Loop
ws.Columns("A:F").AutoFit
Application.DisplayAlerts = True
Application.EnableEvents = True
End Sub
__________________
If you've been given good help, use the icon in that post to give reputation feedback, it is appreciated.
Always put your code between [code] and [/code] tags.
“None of us is as good as all of us” - Ray Kroc
“Actually, I *am* a rocket scientist.” - JB (little ones count!)
|

07-02-2009, 09:05 AM
|
|
Registered User
|
|
Join Date: 09 Mar 2008
Posts: 4
|
|
|
Re: macro to copy specific data from many workbook to one workbook
Thanks J,
Your code is nice and it run, but the files are Protected.
On running code it give an Run Time Error 1004.
Kindly Help
|

07-02-2009, 09:15 AM
|
 |
Forum Guru
|
|
Join Date: 21 Mar 2008
Location: Bakersfield, CA
MS Office Version:2003 (can read 2007 files)
Posts: 9,470
|
|
|
Re: macro to copy specific data from many workbook to one workbook
Please provide all the information regarding how they are protected. Sheets/Books/Password or not?
__________________
If you've been given good help, use the icon in that post to give reputation feedback, it is appreciated.
Always put your code between [code] and [/code] tags.
“None of us is as good as all of us” - Ray Kroc
“Actually, I *am* a rocket scientist.” - JB (little ones count!)
|

07-02-2009, 09:32 AM
|
|
Registered User
|
|
Join Date: 09 Mar 2008
Posts: 4
|
|
|
Re: macro to copy specific data from many workbook to one workbook
Hi J
It is protected in following way
Tools\Protection\Protect Sheet
It is password protected for editing
|

07-02-2009, 09:58 AM
|
 |
Forum Guru
|
|
Join Date: 21 Mar 2008
Location: Bakersfield, CA
MS Office Version:2003 (can read 2007 files)
Posts: 9,470
|
|
|
Re: macro to copy specific data from many workbook to one workbook
Add the highlighted line of code where shown:
Code:
Do While Len(strFileName) > 0
Set wbkOld = Workbooks.Open(strPath & strFileName)
ActiveSheet.Protect Password:="1234", UserInterfaceOnly:=True
Range("A1:F1").AutoFilter
Range("A1:F1").AutoFilter Field:=6, Criteria1:="Delayed"
__________________
If you've been given good help, use the icon in that post to give reputation feedback, it is appreciated.
Always put your code between [code] and [/code] tags.
“None of us is as good as all of us” - Ray Kroc
“Actually, I *am* a rocket scientist.” - JB (little ones count!)
|

07-05-2009, 10:09 AM
|
|
Registered User
|
|
Join Date: 09 Mar 2008
Posts: 4
|
|
|
Re: macro to copy specific data from many workbook to one workbook
Thanks Dear
|

07-05-2009, 01:14 PM
|
 |
Forum Guru
|
|
Join Date: 21 Mar 2008
Location: Bakersfield, CA
MS Office Version:2003 (can read 2007 files)
Posts: 9,470
|
|
|
Re: macro to copy specific data from many workbook to one workbook
If that takes care of your need, be sure to EDIT your original post, click on GO ADVANCED and set the PREFIX box to [Solved].
__________________
If you've been given good help, use the icon in that post to give reputation feedback, it is appreciated.
Always put your code between [code] and [/code] tags.
“None of us is as good as all of us” - Ray Kroc
“Actually, I *am* a rocket scientist.” - JB (little ones count!)
|
 |
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|