+ Reply to Thread
Results 1 to 12 of 12

Filtering Data and copying only filtered results

Hybrid View

  1. #1
    Registered User
    Join Date
    02-19-2013
    Location
    Leeds, England
    MS-Off Ver
    Office 365
    Posts
    87

    Filtering Data and copying only filtered results

    I want to filter the data in one Workbook based on "Department Number" which produces about 10 lines which match the filter but these are on non-sequential lines within the data. I then want to copy only these 10 lines so that I can paste them into another Workbook.
    Can anyone help me please?

  2. #2
    Registered User
    Join Date
    01-19-2009
    Location
    UK
    MS-Off Ver
    2007
    Posts
    60

    Re: Filtering Data and copying only filtered results

    Highlight the cells, Ctrl + G, Visible Cells Only, OK.

    Now only the visible cells are selected, you can copy and paste to another workbook.

    Does this help?
    .
    - AKK9 -

  3. #3
    Registered User
    Join Date
    02-19-2013
    Location
    Leeds, England
    MS-Off Ver
    Office 365
    Posts
    87

    Re: Filtering Data and copying only filtered results

    Many thanks for your suggestion. I am trying to do this within a macro so I think the VB solution I have been given will be better. Thanks again

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Filtering Data and copying only filtered results

    This would assume your criteria is in Column A.

    Sub bigfishprf()
    
    Dim lr As Long
    
    lr = Cells(Rows.Count, 1).End(xlUp).Row
    
    With Range("A2:A" & lr)
    
        .AutoFilter 1, "Department Number"
        .SpecialCells(xlCellTypeVisible).EntireRow.Copy Workbooks("another workbook.xls").Sheets("Sheet1").Range("A" & Rows.Count).End(3)(2)
        
    End With
    
    ActiveSheet.AutoFilterMode = False
    
    End Sub

  5. #5
    Registered User
    Join Date
    02-19-2013
    Location
    Leeds, England
    MS-Off Ver
    Office 365
    Posts
    87

    Re: Filtering Data and copying only filtered results

    Hi John

    Thanks for your help. It all works perfectly. I am a novice to VB so trying to teach myself in bits. The code you have given me is part of my answer and I will now work on the rest....... I might be back for some more help later tho

    Cheers

  6. #6
    Registered User
    Join Date
    02-19-2013
    Location
    Leeds, England
    MS-Off Ver
    Office 365
    Posts
    87

    Re: Filtering Data and copying only filtered results

    Hi John, I said I might need more help.....
    If I want to filter the "Department Number" based on a vale in a specific cell on a different sheet in the workbook, how can I do this?

    Hope you can help

    Paul

  7. #7
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Filtering Data and copying only filtered results

    Not sure I understand but if I do try this:

    Sub bigfishprf()
    
    Dim lr As Long
    
    lr = Cells(Rows.Count, 1).End(xlUp).Row
    
    With Range("A2:A" & lr)
    
        .AutoFilter 1, Sheets("Different sheet").Range("A1").VALUE
        .SpecialCells(xlCellTypeVisible).EntireRow.Copy Workbooks("another workbook.xls").Sheets("Sheet1").Range("A" & Rows.Count).End(3)(2)
        
    End With
    
    ActiveSheet.AutoFilterMode = False
    
    End Sub

  8. #8
    Registered User
    Join Date
    02-19-2013
    Location
    Leeds, England
    MS-Off Ver
    Office 365
    Posts
    87

    Re: Filtering Data and copying only filtered results

    Thanks John, you understand perfectly. I had a , before the Range rather than a . which is why it would not work!

    Any chance I can ask 2 questions?
    1. In your original code, the paste into the other workbook is perfectly located at cell A107. How does your code know where to paste it?
    2. If I wanted to wrap some code around it so that the macro loops round until the Value in the Filter Cell in the other Worksheet ="XXX" at which point it should finish. Is that something you could help me with? Current code shown below

    Again, many thanks

       Sub bigfishprf()
    ' Section 1 - Copy Stores'
    '
        Sheets("Stores").Select
        Range("A2:A500").Select
        Selection.Copy
        Range("b2").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Sheets("Staff").Select
    '
    '  Section 2 - Open Timesheet Master Template
    '  I WOULD WANT TO CHECK HERE IF Sheets("Stores").Range("B2").Value = "XXX".  If it does
    ' then repeat the rest of the code in the Macro 1 more time.  If it does ="XXX" then
    ' the processing is complete
    '
        Workbooks.Open Filename:= _
            "F:\PRF Docs\Grainstore Ltd\Antler\FINAL TEMPLATES\Retail Timesheet MasterTemplate.xlsx"
        Windows("Retail Staff List.xlsm").Activate
    '
    '  Section - 3 - Create Timesheet for next store in list
    '
    Dim lr As Long
    
    lr = Cells(Rows.Count, 1).End(xlUp).Row
    
    With Range("A2:A" & lr)
    
        .Autofilter 7, Sheets("Stores").Range("B2").Value
        .SpecialCells(xlCellTypeVisible).EntireRow.Copy Workbooks("Retail Timesheet MasterTemplate.xlsx").Sheets("Parameters").Range("A" & Rows.Count).End(3)(2)
        
    End With
    
    ActiveSheet.AutoFilterMode = False
     Rows("1:1").Select
        Selection.Autofilter
    ' Section 4 - Prepare Store List for next store
    '
     Sheets("Stores").Select
        Range("B3:B500").Select
        Selection.Copy
        Range("B2").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
    End Sub
    Last edited by bigfishprf; 03-05-2013 at 09:37 AM. Reason: Missed Tags!

  9. #9
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Filtering Data and copying only filtered results

    This line places the copied row to the next available row.

    Workbooks("Retail Timesheet MasterTemplate.xlsx").Sheets("Parameters").Range("A" & Rows.Count).End(3)(2)

    I'm very busy at the moment running my monthly reports and won't be able to comply with your other requirement. If no one else helps then later I'll take a look at it.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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