+ Reply to Thread
Results 1 to 3 of 3

Using conditional statements to copy specific rows to a new sheet

Hybrid View

  1. #1
    Registered User
    Join Date
    06-28-2017
    Location
    Boston, MA
    MS-Off Ver
    365 ProPlus Version 1701
    Posts
    5

    Using conditional statements to copy specific rows to a new sheet

    Hi Everyone,

    I've found a lot of material on this topic but can't get it to work for my purposes.

    I'm working to reformat some desired data on a new sheet with a macro based on specific values in the "E" column. I'm hoping to copy over all the rows that don't have the "Fail" in the "E" column. An example of my raw data file is attached.

    The final format i'm looking for on my new sheet is with the wanted "E" values in the new column "B", the original "B" values in the new column "C", and the original "C"/"D" values in new columns "D"/E" respectively.

    Here's my attempt but I can't figure out what I need to do to fix it:

    Sub Macro_2()
    Dim ClassType As Variant
    Dim ClassArea As Areas
    Dim ClassRange As Range, r As Range
    Dim n As Long
    Set ClassRange = Sheets("Macro Clean Data").Columns(5)
    
    With Sheets("Macro Final Data")
        For Each ClassType In ClassRange
            If ClassType <> "Fail" Then
                n = n + 1
                .Cells(n, 2).Value = ClassType
                .Cells(n, 3).Value = r(, -3).Value
                .Cells(n, 4).Value = r(, -2).Value
                .Cells(n, 5).Value = r(, -1).Value
            Next
        Next
        .Columns.AutoFit
        End With
    End Sub
    Help would be greatly appreciated, Thank you!!
    Attached Files Attached Files

  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: Using conditional statements to copy specific rows to a new sheet

    Try this:

    Sub GabrielJames(): Dim U As Range
    Set U = ActiveSheet.UsedRange
    U.AutoFilter Field:=5, Criteria1:="=" & "Fail"
    U.SpecialCells(xlCellTypeVisible).EntireRow.Delete
    ActiveSheet.AutoFilterMode = False
    Columns(5).Cut
    Columns(2).Insert
    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 Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Using conditional statements to copy specific rows to a new sheet

    You're welcome and thanks for the rep!

+ 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] Copy rows with specific text in specific column into specific sheet
    By Valemaar in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 08-22-2014, 03:23 PM
  2. Replies: 0
    Last Post: 04-11-2013, 05:33 PM
  3. Replies: 0
    Last Post: 09-17-2012, 11:10 AM
  4. [SOLVED] Copy data from specific rows from sheet 1 to sheet 2
    By XFILES999 in forum Excel Programming / VBA / Macros
    Replies: 27
    Last Post: 05-01-2012, 05:12 AM
  5. Conditional copy of specific cells to another sheet
    By Anra in forum Excel Programming / VBA / Macros
    Replies: 25
    Last Post: 10-26-2010, 03:05 PM
  6. Copy specific rows from one sheet to another
    By MartenK in forum Excel General
    Replies: 2
    Last Post: 08-10-2010, 11:36 AM
  7. Copy specific rows to another sheet
    By cevatyildiz in forum Excel General
    Replies: 6
    Last Post: 02-26-2009, 07:38 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