+ Reply to Thread
Results 1 to 5 of 5

Open file dynamically and copy data using advanced filter

Hybrid View

4gurus Open file dynamically and... 09-03-2013, 10:20 AM
fredlo2010 Re: Open file dynamically and... 09-03-2013, 08:23 PM
fredlo2010 Re: Open file dynamically and... 09-03-2013, 08:37 PM
4gurus Re: Open file dynamically and... 09-10-2013, 07:28 AM
arlu1201 Re: Open file dynamically and... 09-11-2013, 07:06 AM
  1. #1
    Registered User
    Join Date
    02-11-2013
    Location
    Bangalore
    MS-Off Ver
    Excel 2007 or Excel 2010.
    Posts
    65

    Open file dynamically and copy data using advanced filter

    Hi,

    I am newbie to excel vba and need your vba help.

    My question:

    Let's say I have an Output file open and I am on a particular sheet (active sheet) and when I run the macro it should give an option to open a particular file (get open filename) and after selecting the file it should filter the data from the selected file (in this case it is raw file and then use advance filter and copy and paste from raw file to output file which is open)

    Note:
    There is only one sheet in Raw file from where macro should pull the data and paste it into Output file (active sheet)

    Please help.

    Thanks!
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Open file dynamically and copy data using advanced filter

    whats the criteria for your filter?

  3. #3
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Open file dynamically and copy data using advanced filter

    Here is a code I made for you. I am asuming that the criteria to filter are the names in column L in your sheet

    Sub ImportFilteredData()
    
    Dim wbOriginal As Workbook
    Dim fileToOpen As String
    Dim rng As Range
    Dim lrow As Long
    Dim lrowFilter As Long
    Dim lrowRaw As Long
    
    application.screenupdating=false
    Set wbOriginal = ActiveWorkbook
    'find the last row of data
    
    With wbOriginal.Sheets("Sheet1")
        lrow = .Cells(Rows.Count, 1).End(xlUp).Row + 1
        lrowFilter = .Cells(Rows.Count, 12).End(xlUp).Row
        
        'open the new file
        fileToOpen = Application.GetOpenFilename
        Workbooks.OpenText fileName:=fileToOpen
          
        For Each rng In .Range("L2:L" & lrowFilter)
            lrowRaw = ActiveWorkbook.Sheets(1).Cells(Rows.Count, 1).End(xlUp).Row
            'filter the data
            ActiveSheet.Range("$A$1:$F$" & lrowRaw).AutoFilter Field:=1, Criteria1:=rng.Value
            
            'copy the data
            ActiveWorkbook.Sheets(1).Range("A2:F" & Cells(Rows.Count, 1).End(xlUp).Row).Copy _
            Destination:=wbOriginal.Sheets(1).Cells(lrow, 1)
            lrow = .Cells(Rows.Count, 1).End(xlUp).Row + 1
            ActiveSheet.Range("$A$1:$F$" & lrowRaw).AutoFilter Field:=1
        Next
    End With
    
    'close the data workbook
    Application.DisplayAlerts = False
        ActiveWorkbook.Close
    Application.DisplayAlerts = True
    application.screenupdating=true
    
    End Sub
    Thanks

  4. #4
    Registered User
    Join Date
    02-11-2013
    Location
    Bangalore
    MS-Off Ver
    Excel 2007 or Excel 2010.
    Posts
    65

    Re: Open file dynamically and copy data using advanced filter

    Thank you so much fredlo2010; works brilliantly

  5. #5
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Open file dynamically and copy data using advanced filter

    Based on your last post in this thread, its apparent that you are satisfied with the solution(s) you've received and have solved your question, but you haven't marked your thread as "SOLVED". I will do it for you this time.

    In future, to mark your thread as Solved, you can do the following -
    Select Thread Tools-> Mark thread as Solved.

    Incase your issue is not solved, you can undo it as follows -
    Select Thread Tools-> Mark thread as Unsolved.

    Also, since you are relatively new to the forum, i would like to inform you that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post which helped you. This adds to the reputation of the person who has taken the time to help you.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Dynamically hide rows for dynamic criteria range of advanced filter
    By Senator685 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-25-2013, 02:08 PM
  2. advanced filter - button to re apply advanced filter across multiple sheets
    By motmac87 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-05-2013, 11:16 PM
  3. Dynamically Updating Chart - Multiple Series based on Advanced Filter
    By alexbell2 in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 11-12-2012, 06:52 AM
  4. [SOLVED] open variably named file, copy/paste data into consolidation file, open next file in list
    By sllawrence1968 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-29-2012, 09:49 PM
  5. Open the latest file to copy and paste data in another file
    By mmf in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-07-2008, 10:41 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1