+ Reply to Thread
Results 1 to 11 of 11

Filter and copy data

Hybrid View

  1. #1
    Registered User
    Join Date
    12-04-2013
    Location
    Melbourne
    MS-Off Ver
    Excel 2007
    Posts
    92

    Filter and copy data

    Hi,

    I have a excell sheet with some data.

    I want to filter the daca and copy it to Sheet 2,

    For example

    In sheet 2 I have
    A1 = Nike
    B1 = Puma


    In sheet 1 I have lots of Nike and Puma products.

    I want to make a macro to fliter sheet 1 so that Column A in sheet 1 get filtered by contains Puma. than select all filtered result, copy it and paste transpose in Sheet 2 row B next to Puma.

    I have more products, this is jsust to explain what i need to do.

    Any help is appriciated.

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Filter and copy data

    Hi,

    Here's a beginning:

    Sub Whar()
    Dim w1 As Worksheet, w2 As Worksheet, ToGet As String
    GetProduct:            ToGet = InputBox("What Product?")
                            If ToGet = "" Then Exit Sub
            Set w1 = Sheets("Sheet1"): Set w2 = Sheets("Sheet2")
            ws.Range("A1").CurrentRegion.AutoFilter Field:=1, Criteria1:=ToGet
            
            w1.UsedRange.SpecialCells(xlCellTypeVisible).Copy
            w2.Range("B1").PasteSpecial Transpose:=True
    End Sub
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Forum Contributor
    Join Date
    08-17-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    132

    Re: Filter and copy data

    How they are categorized ....in column A (Sheet 1) to identify which product is for which brand?

    Attach a sample file..please...

    Regards,
    BS

  4. #4
    Registered User
    Join Date
    12-04-2013
    Location
    Melbourne
    MS-Off Ver
    Excel 2007
    Posts
    92

    Re: Filter and copy data

    Hi BS,

    I have attached the template file.
    So prety much form Sheet 1 (MAINT) I wanto filter all products with name Puma and copy the filtered data and paset it in Sheet2, row 2 next to Puma, so paste spacial, transform.

    I have created a macro using record function

    Sub Macro2()
    '
    ' Macro2 Macro
        Range("A2").Select
        ActiveCell.FormulaR1C1 = "Puma"
        Sheets("MAINT").Select
        ActiveSheet.Range("$A$1:$A$12").AutoFilter Field:=1, Criteria1:="=*Puma*", _
            Operator:=xlAnd
        Range("A1:A11").Select
        Selection.Copy
        Sheets("MAINT_LINKING").Select
        Range("B2").Select
        Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=True
        Range("A3").Select
    End Sub
    This is what I want to do but I want to automaticaly filter copy everything using a macro like this.
    Thanks
    Attached Files Attached Files

  5. #5
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Filter and copy data

    Hi,

    Try this:Thar.xlsm

  6. #6
    Registered User
    Join Date
    12-04-2013
    Location
    Melbourne
    MS-Off Ver
    Excel 2007
    Posts
    92

    Re: Filter and copy data

    Hi xladept

    This is exactly what I want to do. However, In my original document, in Sheet 1 there are some other information in other columns D E F etc).
    Does this affect when copying the filtered data? t doesnt work as good when I have values in columns other than A.

    Thankyou for your help


    PS: the problem is If I put "Pants - Nike" or the product after some leters, it doesnt get filtered. How do I fix this?
    Last edited by tharindudk; 02-02-2014 at 09:32 PM.

  7. #7
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Filter and copy data

    Hi Thar,

    This seems to work:

    Sub Filter()
    Dim w1 As Worksheet, w2 As Worksheet, ToGet As String, r As Long
    Set w1 = Sheets("MAINT"): Set w2 = Sheets("MAINT_LINKING")
    GetProduct:  For r = 2 To w2.Range("A" & Rows.Count).End(xlUp).Row
                        ToGet = Range("A" & r) & "*"
                            If ToGet = "" Then Exit Sub
            
            w1.Range("A2").CurrentRegion.AutoFilter Field:=1, Criteria1:=ToGet
            
            w1.UsedRange.Offset(1).Resize(, 1).SpecialCells(xlCellTypeVisible).Copy
            w2.Range("B" & r).PasteSpecial Transpose:=True
            Next r
            w1.AutoFilterMode = False
            Application.CutCopyMode = False
    End Sub
    Last edited by xladept; 02-02-2014 at 10:09 PM.

  8. #8
    Registered User
    Join Date
    12-04-2013
    Location
    Melbourne
    MS-Off Ver
    Excel 2007
    Posts
    92

    Re: Filter and copy data

    Hi, unfortunately when I copy this, it is still the same

  9. #9
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Filter and copy data

    Hi Thar,

    Thanks for the rep!

    One more wildcard - try it now

    Sub Filter()
    Dim w1 As Worksheet, w2 As Worksheet, ToGet As String, r As Long
    Set w1 = Sheets("MAINT"): Set w2 = Sheets("MAINT_LINKING")
    GetProduct:  For r = 2 To w2.Range("A" & Rows.Count).End(xlUp).Row
                        ToGet = "*" & Range("A" & r) & "*"
                            If ToGet = "" Then Exit Sub
            
            w1.Range("A2").CurrentRegion.AutoFilter Field:=1, Criteria1:=ToGet
            
            w1.UsedRange.Offset(1).SpecialCells(xlCellTypeVisible).Copy
            w2.Range("B" & r).PasteSpecial Transpose:=True
            Next r
            w1.AutoFilterMode = False
            Application.CutCopyMode = False
    End Sub

  10. #10
    Registered User
    Join Date
    12-04-2013
    Location
    Melbourne
    MS-Off Ver
    Excel 2007
    Posts
    92

    Re: Filter and copy data

    Hi,

    Thankyou for your help. It works fine now

  11. #11
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Filter and copy data

    You're welcome!

+ 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. Macro to filter data and copy the data's from multiple columns based on the criteria
    By millatshawn in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-22-2014, 08:14 AM
  2. Macro that can filter excel data and copy the filtered data to another worksheet
    By glide2131 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-10-2013, 02:43 PM
  3. filter and copy data to another ws
    By kontti in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-22-2011, 08:19 AM
  4. How to copy out filter data
    By wei82 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 04-24-2007, 05:56 AM
  5. How we can copy data when there is filter
    By dalipsinghbisht in forum Excel General
    Replies: 3
    Last Post: 03-21-2006, 08:07 AM

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