+ Reply to Thread
Results 1 to 5 of 5

Copy row based on Cell value.

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-16-2008
    Location
    Mansfield, TX
    Posts
    324

    Copy row based on Cell value.

    Hello, I have been using the macro below that I recorded to copy rows of data the Weekly Data sheet to the Report sheet based on the cell value. It is working well, but I would like to build some logic into it so that it will not copy any row that already exists in the target sheet. There will never be a repeating row of data in the spreadsheet so you could use the combination of the values in columns A&D in the Weekly Data sheet to compare to the values in columns A&D in the Report sheet. Sample Data is attached.

      ActiveSheet.Range("$A$1:$EL$732").AutoFilter Field:=10, Criteria1:="<60", _
            Operator:=xlAnd
        Range("A2").Select
        Range("A2:J2", Selection.End(xlDown)).Select
        Application.CutCopyMode = False
        Selection.Copy
        Sheets("Report").Paste
    Thanks for any guidance!

    Clayton
    Attached Files Attached Files
    Last edited by dcgrove; 05-06-2011 at 10:01 AM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Copy row based on Cell value.

    Try this:

    Option Explicit
    
    Sub CopyFilterSpecial()
    Dim LR As Long
    Application.ScreenUpdating = False
    
    With Sheets("Weekly Data")
        LR = .Range("A" & .Rows.Count).End(xlUp).Row
        .Range("HH1") = "key"
        .Range("HH2:HH" & LR).FormulaR1C1 = _
            "=IF(RC10<60,NOT(ISNUMBER(MATCH(RC1&""-""&RC4,INDEX(Report!R2C1:R1000C1&""-""&Report!R2C4:R1000C4,0),0))),FALSE)"
        .Range("HH2:HH" & LR).Value = .Range("HH2:HH" & LR).Value
        .AutoFilterMode = False
        .Rows(1).AutoFilter
        .Rows(1).AutoFilter Field:=216, Criteria1:="TRUE"
        LR = .Range("A" & .Rows.Count).End(xlUp).Row
        If LR > 1 Then .Range("A2:EL" & LR).Copy _
            Sheets("Report").Range("A" & Rows.Count).End(xlUp).Offset(1)
        .AutoFilterMode = False
        .Columns(216).ClearContents
        .Range("A1").CurrentRegion.AutoFilter
    End With
    
    Application.ScreenUpdating = True
    End Sub
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Copy row based on Cell value.

    Let's do some codecleaning first:

    with ActiveSheet.Range("$A$1:$EL$732")
      .AutoFilter 10, "<60"
      .offset(1).copy Sheets("Report").cells(rows.count,1).end(xlup).offset
    (1)
      .Autofilter
    end with



  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Copy row based on Cell value.

    Nevermind, not worth getting into.

  5. #5
    Forum Contributor
    Join Date
    02-16-2008
    Location
    Mansfield, TX
    Posts
    324

    Re: Copy row based on Cell value.

    Jerry, not entirely sure what I missed, but thanks for the help! I can always count on your suggestions to be top notch!

    Clayton Grove

+ 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