+ Reply to Thread
Results 1 to 12 of 12

How to move rows based on cell value to multiple tabs?

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-19-2016
    Location
    Alaska
    MS-Off Ver
    MS 2010, 2013, 2016
    Posts
    272

    How to move rows based on cell value to multiple tabs?

    Hi everyone I have the macro below that works well. I just need to expand on it and need some guidance.

    It currently moves data found in sheet 1 to sheet 2 if the values in column F = "Y". First, I would like the formulas on columns F:I to be copied to the last cell with data. Then, I need more conditions, for example if any cell in column "G" = No Issues Found, move to sheet 3, if cells in column "H" = Review then move to sheet 4 and if the cell in column "I" equals "Test Fail" then move to sheet5.

    Biggest issue I'm thinking is that some rows MIGHT need to be in multiple tabs but everything I found in Google deletes the row once it meets the first criteria.

    Sub MoveData()
    
        Dim xRg As Range
        Dim xCell As Range
        Dim I As Long
        Dim J As Long
        Dim K As Long
        Dim L As Long
        
        I = Worksheets("Sheet1").UsedRange.Rows.count
        J = Worksheets("Sheet2").UsedRange.Rows.count
        If J = 1 Then
           If Application.WorksheetFunction.CountA(Worksheets("Sheet2").UsedRange) = 0 Then J = 0
        End If
        Set xRg = Worksheets("Sheet1").Range("F1:F" & I)
        On Error Resume Next
        Application.ScreenUpdating = False
        For K = 1 To xRg.count
            If CStr(xRg(K).Value) = "Y" Then
                xRg(K).EntireRow.Copy Destination:=Worksheets("Sheet2").Range("A" & J + 2)
                xRg(K).EntireRow.Delete
                If CStr(xRg(K).Value) = "Y" Then
                    K = K - 1
                End If
                J = J + 1
            End If
        Next
        Application.ScreenUpdating = True
    End Sub
    Attached Files Attached Files
    Last edited by AccountingJ; 08-17-2020 at 12:57 PM.

  2. #2
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,520

    Re: How to move rows based on cell value to multiple tabs?

    Hi AccountingJ...
    As an example...See attached file...
    Sub sintek()
    Dim Crit, i As Long
    Crit = Array("Y", "No Issues Found", "Review", "Test Fail")
    With Sheets("Data")
        .Range("G2:I2").Copy .Range("G3").Resize(.Cells(.Rows.Count, 1).End(xlUp).Row - 2)
        For i = LBound(Crit) To UBound(Crit)
            With .Cells(1).CurrentRegion
                .AutoFilter i + 6, Crit(i)
                .SpecialCells(12).Copy Sheets(Crit(i)).Range("A1")
                .AutoFilter
            End With
        Next i
    End With
    End Sub
    Attached Files Attached Files
    Last edited by Sintek; 08-12-2020 at 08:47 AM.
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  3. #3
    Forum Contributor
    Join Date
    09-19-2016
    Location
    Alaska
    MS-Off Ver
    MS 2010, 2013, 2016
    Posts
    272

    Re: How to move rows based on cell value to multiple tabs?

    Wow, thanks, works well.

    Only thing, is that the sheets names need to be named sheet2, sheet3, etc...

  4. #4
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,520

    Re: How to move rows based on cell value to multiple tabs?

    Sub sintek()
    Dim Crit, i As Long
    Crit = Array("Y", "No Issues Found", "Review", "Test Fail")
    With Sheet1
        .Range("G2:I2").Copy .Range("G3").Resize(.Cells(.Rows.Count, 1).End(xlUp).Row - 2)
        For i = LBound(Crit) To UBound(Crit)
            With .Cells(1).CurrentRegion
                .AutoFilter i + 6, Crit(i)
                .SpecialCells(12).Copy Sheets(i + 2).Range("A1")
                .AutoFilter
            End With
        Next i
    End With
    End Sub

    Thanks for rep by the way...

  5. #5
    Forum Contributor
    Join Date
    09-19-2016
    Location
    Alaska
    MS-Off Ver
    MS 2010, 2013, 2016
    Posts
    272

    Re: How to move rows based on cell value to multiple tabs?

    I had to add more columns and pushed back the formulas back to range T2:AA2 and also added some tabs.

    I made the changes to your macro, see below:

    Sub sintek()
    Dim Crit, i As Long
    Crit = Array("Y", "No Issues Found", "Review", "Test Fail", "Test Again", "N", "Audit Issue", "Review Needed")
    With Sheets("Data")
        .Range("T2:AA2").Copy .Range("T3").Resize(.Cells(.Rows.Count, 1).End(xlUp).Row - 2)
        For i = LBound(Crit) To UBound(Crit)
            With .Cells(1).CurrentRegion
                .AutoFilter i + 6, Crit(i)
                .SpecialCells(12).Copy Sheets(Crit(i)).Range("A1")
                .AutoFilter
            End With
        Next i
    End With
    End Sub
    The macro runs but does not transfer over the data like it did before, what other changes do I need to do to it?
    Attached Files Attached Files
    Last edited by AccountingJ; 08-17-2020 at 02:15 PM.

  6. #6
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,520

    Re: How to move rows based on cell value to multiple tabs?

    The macro runs but does not transfer over the data like it did before, what other changes do I need to do to it?
    Will only be able to ascertain issue once I see the file...

  7. #7
    Forum Contributor
    Join Date
    09-19-2016
    Location
    Alaska
    MS-Off Ver
    MS 2010, 2013, 2016
    Posts
    272

    Re: How to move rows based on cell value to multiple tabs?

    Quote Originally Posted by sintek View Post
    Will only be able to ascertain issue once I see the file...
    Sorry, I forgot to attach. Please see above.

  8. #8
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,520

    Re: How to move rows based on cell value to multiple tabs?

    Sub sintek()
    Dim Crit, i As Long
    Crit = Array("Y", "No Issues Found", "Review", "Test Fail", "Test Again", "Audit Issue", "N", "Review Needed") ' ! Keep in order of appearance in Col
    With Sheets("Data")
        .Range("T2:AA2").Copy .Range("T3").Resize(.Cells(.Rows.Count, 1).End(xlUp).Row - 2)
        For i = LBound(Crit) To UBound(Crit)
            With .Cells(1).CurrentRegion
                .AutoFilter i + 20, Crit(i)
                .SpecialCells(12).Copy Sheets(Crit(i)).Range("A1")
                .AutoFilter
            End With
        Next i
    End With
    End Sub

  9. #9
    Forum Contributor
    Join Date
    09-19-2016
    Location
    Alaska
    MS-Off Ver
    MS 2010, 2013, 2016
    Posts
    272

    Re: How to move rows based on cell value to multiple tabs?

    thanks, what does the 20 do? that's the only change I see.

  10. #10
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,520

    Re: How to move rows based on cell value to multiple tabs?

    Changes in red...
    Crit = Array("Y", "No Issues Found", "Review", "Test Fail", "Test Again", "Audit Issue", "N", "Review Needed") ' ! Keep in order of appearance in Col
    .AutoFilter i + 20, Crit(i) '! i starts at 0 so i + 20 is Col Number 20 to filter first Crit i.e "Y" and so on...

  11. #11
    Forum Contributor
    Join Date
    09-19-2016
    Location
    Alaska
    MS-Off Ver
    MS 2010, 2013, 2016
    Posts
    272

    Re: How to move rows based on cell value to multiple tabs?

    oh, thanks a lot!

  12. #12
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,520

    Re: How to move rows based on cell value to multiple tabs?

    pleasure...

+ 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. [SOLVED] Move Rows to different Sheets based on Cell value(s) with Multiple Buttons
    By SeventySix in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-31-2019, 04:25 PM
  2. [SOLVED] VBA Change Event, Move multiple rows based on drop down selection for multiple criteria
    By Webbers in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-02-2017, 11:51 AM
  3. move rows to new sheet based on text and date in multiple sheets
    By myjebay1 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-06-2014, 02:39 PM
  4. [SOLVED] Macros To Move Multiple Rows To Another Sheet And Macro To Move Single Rows To DAX Table
    By jcaynes in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-22-2013, 05:08 PM
  5. Replies: 1
    Last Post: 03-17-2013, 06:52 AM
  6. [SOLVED] Select rows based on date range and copy to multiple tabs
    By B-Rell in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-01-2012, 09:27 AM
  7. Replies: 1
    Last Post: 04-05-2012, 07:48 PM

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