+ Reply to Thread
Results 1 to 12 of 12

Copy unique rows based on two cell values

Hybrid View

  1. #1
    Registered User
    Join Date
    02-26-2013
    Location
    Engerland
    MS-Off Ver
    Excel 20011
    Posts
    13

    Copy unique rows based on two cell values

    I have a sheet named 'Sales' where invoice data is stored. In cell 'A16' is a list of the customers from which I want to select a customer and then copy all rows where that customer's name is and also where the 'Paid' cell value is set to 'No'. I want to copy it to the 'Statements' sheet from cell 'C14' downward. I've managed to hack some code I've found and this currently will copy all the rows to the 'Statements2' sheet but not based on the customer's name or whether they've paid. I've attached the workbook.
    Many thanks
    Attached Files Attached Files

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2505 Win 11
    Posts
    24,743

    Re: Copy unique rows based on two cell values

    @ArtySin
    When I downloaded your file a virus was attached as a temp file. Fortunately, Norton spotted it and gave it the heave-ho. You may want to check your files with an anti-virus program.

    Working on your problem. Will post separately.

    Alan
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    02-26-2013
    Location
    Engerland
    MS-Off Ver
    Excel 20011
    Posts
    13

    Re: Copy unique rows based on two cell values

    Quote Originally Posted by alansidman View Post
    @ArtySin
    When I downloaded your file a virus was attached as a temp file. Fortunately, Norton spotted it and gave it the heave-ho. You may want to check your files with an anti-virus program.

    Working on your problem. Will post separately.

    Alan
    Alan, I keep my files on Dropbox so I was surprised you found a virus. I scanned them anyway but found nothing so rather strange.

  4. #4
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Copy unique rows based on two cell values

    strange i just scanned it with avg and superantispyware and its fine
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  5. #5
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2505 Win 11
    Posts
    24,743

    Re: Copy unique rows based on two cell values

    I guess I was just lucky.

    Anyway, ArtySin, I think that a solution for you would be to employ the Advanced Filter function.

    Here is a link to how to do it.

    http://www.contextures.com/xladvfilter01.html

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Copy unique rows based on two cell values

    Like Alan, I have also Norton and was warned to remove the file.

  7. #7
    Registered User
    Join Date
    02-26-2013
    Location
    Engerland
    MS-Off Ver
    Excel 20011
    Posts
    13

    Re: Copy unique rows based on two cell values

    @Alan, Looked at the advanced filters link and all works fine. However, a problem arises when converting this to vba as the person who will run this is a bit of a technophobe which is why I wanted to do this using vba assigned to a macro button. For example vba created to copy the filtered data may look like:
    Sub copyFltr()
        Range("A8:E14").Select
        Selection.Copy
        Sheets("Statements").Select
        Range("C14").Select
        Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=False
    End Sub
    but when a different customer is selected Range("A8:E14") will change to e.g. Range("A3:E14") so the first few rows will not get copied over. The s/sheet I uploaded is just a smaller version of a much larger sheet where there are over 200 rows of invoice data so this problem will be worse. If you Guys could come up with some code to lookup the customer's name and only copy those rows over to the statements sheet. it would be much appreciated.
    Many thanks

  8. #8
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2505 Win 11
    Posts
    24,743

    Re: Copy unique rows based on two cell values

    I am unable to help you. I tried to download your file again in order to write some code and Norton removed it as viral. Hopefully, you can fix this and repost the file or someone else will be able to help you.

    Alan

  9. #9
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Copy unique rows based on two cell values

    maybe norton is detecting false positives in excel 2011 files? any way the op has Excel 20011 so maybe norton has never heard of that
    here it is again downloaded and re-saved in excel 2007
    Attached Files Attached Files
    Last edited by martindwilson; 02-17-2014 at 02:10 PM.

  10. #10
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2505 Win 11
    Posts
    24,743

    Re: Copy unique rows based on two cell values

    @Martin;
    Attached Images Attached Images
    Last edited by alansidman; 02-17-2014 at 02:17 PM.

  11. #11
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Copy unique rows based on two cell values


  12. #12
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2505 Win 11
    Posts
    24,743

    Re: Copy unique rows based on two cell values

    Thanks to Martin, I was able to get a clean copy of the file

    Here is the code that should do it for you. I did move your criteria combobox to I1:I2 on the Sales Sheet. I would also suggest that you change the combo box on the invoice sheet to a formula that reads =Sales!I2

    Sub FilterC()
    'Filter Copy and Paste
    'AMSidman 2/17/14
    
        Dim w1 As Worksheet
        Set w1 = Sheets("Sales")
        Dim w2 As Worksheet
        Set w2 = Sheets("Statements")
        Dim lr As Long
        lr = Range("A" & Rows.Count).End(xlUp).Row
        Dim sCrit As String
        sCrit = Range("I2").Value
        Dim c As Range
    
        Application.ScreenUpdating = False
        With w1
            .AutoFilterMode = False
            .Range("A1:G" & lr).AutoFilter Field:=6, Criteria1:=sCrit
            .Range("A1:G" & lr).AutoFilter Field:=7, Criteria1:="No"
            .Range("A2:E" & lr).SpecialCells(xlCellTypeVisible).Copy
            w2.Range("C14").PasteSpecial xlPasteValues
        End With
        Application.CutCopyMode = False
        fRng.AutoFilter
        Application.ScreenUpdating = True
        MsgBox ("Action Completed")
        
    End Sub

+ 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. Compare two sheets,copy and paste unique rows based on values in 2 columns
    By ooggiemobile in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-02-2013, 03:58 AM
  2. copy rows based on cell values
    By Galactico076 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-01-2013, 10:49 AM
  3. [SOLVED] Macro - Copy and Combine values in cell and paste it in other cells based on Unique ID
    By haleakala17 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-11-2012, 05:41 PM
  4. Copy Rows and Paste Based On Cell Values
    By boohah in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-08-2010, 08:58 AM
  5. [SOLVED] Can I automate copy of rows based on cell values
    By rveach64 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-20-2005, 02:25 PM

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