+ Reply to Thread
Results 1 to 12 of 12

Move entire row to another worksheet based on cell value

Hybrid View

  1. #1
    Registered User
    Join Date
    12-15-2011
    Location
    Dallas texas
    MS-Off Ver
    Excel 2010
    Posts
    45

    Move entire row to another worksheet based on cell value

    Hello-

    What I'm looking for is a VBA that will copy cells (A,B,C,D,F,G) from Project Pipeline sheet over to Project tracker sheet cells (A,B,C,D,E,F) when Column F has either (TBD,N,C, OR H)



    Here is what ITEST.xlsx have now as a formula that works but also pulls over lines that do not meet that criteria and they are blank on the Project Tracker sheet ( so it's not exatly what im looking for)

    =IF('Project Pipeline'!$N2="TBD",'Project Pipeline'!B2,IF(LEFT('Project Pipeline'!$N2,1)="N",'Project Pipeline'!B2,IF(LEFT('Project Pipeline'!$N2,1)="C",'Project Pipeline'!B2,IF(LEFT('Project Pipeline'!$N2,1)="H",'Project Pipeline'!B2,""))))

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

    Re: Move entire row to another worksheet based on cell value

    Try this code
    Option Explicit
    
    Sub copy_rows()
    Dim lrow As Long, i As Long, lastrow As Long
    
    With Worksheets("Project Pipeline")
        lrow = .Range("A" & .Rows.Count).End(xlUp).Row
        lastrow = Worksheets("Project Tracker").Range("A" & Rows.Count).End(xlUp).Row
        For i = 2 To lrow
            If .Range("F" & i).Value = "TBD" Or .Range("F" & i).Value = "N" Or .Range("F" & i).Value = "C" Or .Range("F" & i).Value = "H" Then
                .Range("A" & i & ":D" & i).Copy Worksheets("Project Tracker").Range("A" & lastrow + 1)
                .Range("F" & i).Copy Worksheets("Project Tracker").Range("E" & lastrow + 1)
                .Range("G" & i).Copy Worksheets("Project Tracker").Range("F" & lastrow + 1)
            End If
        Next i
    End With
    
    End Sub
    Copy the Excel VBA code
    Select the workbook in which you want to store the Excel VBA code
    Hold the Alt key, and press the F11 key, to open the Visual Basic Editor
    Choose Insert | Module
    Where the cursor is flashing, choose Edit | Paste

    To run the Excel VBA code:
    Choose View | Macros
    Select a macro in the list, and click the Run button.
    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]

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

    Re: Move entire row to another worksheet based on cell value

    I'm a fan of using AutoFilter to move all appropriate rows in a single pass, so this non-looping method is one I would employ. (note, your sample sheet has a lot of hidden data way down the sheet, so clear all that in columns A:G before trying this:

    Option Explicit
    
    Sub CopyRows()
    Dim LR As Long, BR As Long, NR As Long
    
    With Sheets("Project Pipeline")
        .AutoFilterMode = False
        LR = .Range("A" & .Rows.Count).End(xlUp).Row
        .Range("I2:I" & LR).FormulaR1C1 = "=OR(OR(LEFT(RC6,1)={""C"",""H"",""N""}, RC6=""TBD""))"
        .Range("I:I").AutoFilter Field:=1
        .Range("I:I").AutoFilter Field:=1, Criteria1:=True
        BR = .Range("A" & .Rows.Count).End(xlUp).Row
        If BR > 1 Then
            NR = Sheets("Project Tracker").Range("A" & Rows.Count).End(xlUp).Row + 1
            .Range("A2:D" & BR & ",F2:G" & BR).Copy Sheets("Project Tracker").Range("A" & NR)
        End If
        .AutoFilterMode = False
        .Range("I:I").ClearContents
    End With
    
    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!)

  4. #4
    Registered User
    Join Date
    12-15-2011
    Location
    Dallas texas
    MS-Off Ver
    Excel 2010
    Posts
    45

    Re: Move entire row to another worksheet based on cell value

    Jerry-

    Thanks that worked awsome. In my acutal spreadsheet i need it to return Column (B,C,D,E,N,O) and its now returning (a,b,c,d,e,f)

    see the modifications i did. can you help me return what i need when i change the range it it gives me a 400 error

    Sub CopyRows()
    Dim LR As Long, BR As Long, NR As Long
    
    With Sheets("Project Pipeline")
        .AutoFilterMode = False
        LR = .Range("A" & .Rows.Count).End(xlUp).Row
        .Range("I2:I" & LR).FormulaR1C1 = "=OR(OR(LEFT(RC14,1)={""C"",""H"",""N""}, RC14=""TBD""))"
        .Range("I:I").AutoFilter Field:=1
        .Range("I:I").AutoFilter Field:=1, Criteria1:=True
        BR = .Range("A" & .Rows.Count).End(xlUp).Row
        If BR > 1 Then
            NR = Sheets("Project Tracker").Range("A" & Rows.Count).End(xlUp).Row + 1
            .Range("A2:D" & BR & ",F2:G" & BR).Copy Sheets("Project Tracker").Range("A" & NR)
        End If
        .AutoFilterMode = False
        .Range("I:I").ClearContents
    End With
    
    End Sub
    Last edited by arlu1201; 06-24-2012 at 06:07 AM. Reason: Corrected code tags.

  5. #5
    Registered User
    Join Date
    12-15-2011
    Location
    Dallas texas
    MS-Off Ver
    Excel 2010
    Posts
    45

    Re: Move entire row to another worksheet based on cell value

    This code works but how do i make it override the info it reported last time when I run/refresh the macro?

    I want it to auto update and that add infoto the bottom when the other rows met criteria

    Can anyone help with this

    See code below

    Sub CopyRows()
    Dim LR As Long, BR As Long, NR As Long
    
    With Sheets("Project Pipeline")
    .AutoFilterMode = False
    LR = .Range("A" & .Rows.Count).End(xlUp).Row
    .Range("I2:I" & LR).FormulaR1C1 = "=OR(OR(LEFT(RC14,1)={""C"",""H"",""N""}, RC14=""TBD""))"
    .Range("I:I").AutoFilter Field:=1
    .Range("I:I").AutoFilter Field:=1, Criteria1:=True
    BR = .Range("A" & .Rows.Count).End(xlUp).Row
    If BR > 1 Then
    NR = Sheets("Project Tracker").Range("A" & Rows.Count).End(xlUp).Row + 1
    .Range("B2:E" & BR & ",M2:N" & BR).Copy Sheets("Project Tracker").Range("A" & NR)
    End If
    .AutoFilterMode = False
    .Range("I:I").ClearContents
    End With
    
    End Sub
    Last edited by arlu1201; 06-24-2012 at 01:19 PM. Reason: This post needed code tags.

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

    Re: Move entire row to another worksheet based on cell value

    As per forum rules, please EDIT your posts above and add CODE and /CODE tags around the VBA as explained in my signature. Lots of useful tips in the FORUM RULES, read the link above.

  7. #7
    Registered User
    Join Date
    12-15-2011
    Location
    Dallas texas
    MS-Off Ver
    Excel 2010
    Posts
    45

    Re: Move entire row to another worksheet based on cell value

    Thought i had already done so.

    Here it is

    Sub CopyRows()
    Dim LR As Long, BR As Long, NR As Long
    
    With Sheets("Project Pipeline")
    .AutoFilterMode = False
    LR = .Range("A" & .Rows.Count).End(xlUp).Row
    .Range("I2:I" & LR).FormulaR1C1 = "=OR(OR(LEFT(RC14,1)={""C"",""H"",""N""}, RC14=""TBD""))"
    .Range("I:I").AutoFilter Field:=1
    .Range("I:I").AutoFilter Field:=1, Criteria1:=True
    BR = .Range("A" & .Rows.Count).End(xlUp).Row
    If BR > 1 Then
    NR = Sheets("Project Tracker").Range("A" & Rows.Count).End(xlUp).Row + 1
    .Range("B2:E" & BR & ",M2:N" & BR).Copy Sheets("Project Tracker").Range("A" & NR)
    End If
    .AutoFilterMode = False
    .Range("I:I").ClearContents
    End With
    
    End Sub
    Last edited by mmctague; 06-24-2012 at 10:26 AM.

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

    Re: Move entire row to another worksheet based on cell value

    Maybe like so:
    Option Explicit
    
    Sub CopyRows()
    Dim LR As Long, BR As Long
    
    With Sheets("Project Pipeline")
        .AutoFilterMode = False
        LR = .Range("A" & .Rows.Count).End(xlUp).Row
        .Range("I2:I" & LR).FormulaR1C1 = "=OR(OR(LEFT(RC14,1)={""C"",""H"",""N""}, RC14=""TBD""))"
        .Range("I:I").AutoFilter Field:=1
        .Range("I:I").AutoFilter Field:=1, Criteria1:=True
        BR = .Range("A" & .Rows.Count).End(xlUp).Row
        If BR > 1 Then
            Sheets("Project Tracker").UsedRange.Offset(1).Clear
            .Range("B2:E" & BR & ",M2:N" & BR).Copy Sheets("Project Tracker").Range("A2")
        End If
        .AutoFilterMode = False
        .Range("I:I").ClearContents
    End With
    
    End Sub

  9. #9
    Registered User
    Join Date
    12-15-2011
    Location
    Dallas texas
    MS-Off Ver
    Excel 2010
    Posts
    45

    Re: Move entire row to another worksheet based on cell value

    Project Pipeline (20120623)-YESv1.xlsmI have attached my spreadsheet to work from maybe i'm not explaning it corretly.I'm looking for it to pull over info to the project pipeline worksheet and then auto pull to the project tracker worksheet when projects get added or updated to meet the criteira set (TBD, N,C,H)and they get added to end of the list on the project tacker worksheet

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

    Re: Move entire row to another worksheet based on cell value

    Back on post #4 we had "that works awesome" to now... what?

    I'm going to have to move on. Sorry if it wasn't awesome enough. I'll ping some others to take a look. Cheers.

  11. #11
    Registered User
    Join Date
    12-15-2011
    Location
    Dallas texas
    MS-Off Ver
    Excel 2010
    Posts
    45

    Re: Move entire row to another worksheet based on cell value

    Thanks for the help.Just was looking for it to do a bit more.

    I will try and figure it out.

    -Mike

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

    Re: Move entire row to another worksheet based on cell value

    If that takes care of your original request, please select Thread Tools from menu above and set this topic to SOLVED.

+ 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