Welcome to the Excel Forum

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.

Please Register to Remove these Ads

Please Register to Remove these Ads



Reply
  #1  
Old 07-01-2009, 01:24 AM
anvesh.pune anvesh.pune is offline
Registered User
 
Join Date: 09 Mar 2008
Posts: 4
anvesh.pune is becoming part of the community
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
Attached Files
File Type: xls RGEN.xls (27.5 KB, 7 views)
Reply With Quote
  #2  
Old 07-01-2009, 02:49 AM
JBeaucaire's Avatar
JBeaucaire JBeaucaire is offline
Forum Guru
 
Join Date: 21 Mar 2008
Location: Bakersfield, CA
MS Office Version:2003 (can read 2007 files)
Posts: 9,470
JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay
Send a message via Skype™ to JBeaucaire
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!)
Reply With Quote
  #3  
Old 07-02-2009, 09:05 AM
anvesh.pune anvesh.pune is offline
Registered User
 
Join Date: 09 Mar 2008
Posts: 4
anvesh.pune is becoming part of the community
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
Reply With Quote
  #4  
Old 07-02-2009, 09:15 AM
JBeaucaire's Avatar
JBeaucaire JBeaucaire is offline
Forum Guru
 
Join Date: 21 Mar 2008
Location: Bakersfield, CA
MS Office Version:2003 (can read 2007 files)
Posts: 9,470
JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay
Send a message via Skype™ to JBeaucaire
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!)
Reply With Quote
  #5  
Old 07-02-2009, 09:32 AM
anvesh.pune anvesh.pune is offline
Registered User
 
Join Date: 09 Mar 2008
Posts: 4
anvesh.pune is becoming part of the community
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
Reply With Quote
  #6  
Old 07-02-2009, 09:58 AM
JBeaucaire's Avatar
JBeaucaire JBeaucaire is offline
Forum Guru
 
Join Date: 21 Mar 2008
Location: Bakersfield, CA
MS Office Version:2003 (can read 2007 files)
Posts: 9,470
JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay
Send a message via Skype™ to JBeaucaire
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!)
Reply With Quote
  #7  
Old 07-05-2009, 10:09 AM
anvesh.pune anvesh.pune is offline
Registered User
 
Join Date: 09 Mar 2008
Posts: 4
anvesh.pune is becoming part of the community
Re: macro to copy specific data from many workbook to one workbook

Thanks Dear
Reply With Quote
  #8  
Old 07-05-2009, 01:14 PM
JBeaucaire's Avatar
JBeaucaire JBeaucaire is offline
Forum Guru
 
Join Date: 21 Mar 2008
Location: Bakersfield, CA
MS Office Version:2003 (can read 2007 files)
Posts: 9,470
JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay
Send a message via Skype™ to JBeaucaire
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!)
Reply With Quote


Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Forum Jump