+ Reply to Thread
Results 1 to 4 of 4

Moving rows into a new worksheet if colour or cell = a specified colour or term

Hybrid View

  1. #1
    Registered User
    Join Date
    07-13-2009
    Location
    Cheltenham, England
    MS-Off Ver
    Excel 2003
    Posts
    7

    Moving rows into a new worksheet if colour or cell = a specified colour or term

    Hi, I need some help please...

    Looking at the main worksheet "Q1 Jul 2009" I would like to move an entire row to a new worksheet based on one or more of the following attributes:

    1. Row is coloured either green or red.
    2. Column "P" has either "won", "lost" or "superseded"

    If the row is green or the cell in column P is "won" then the row should be moved to worksheet "Won".

    If the row is red or the cell in column P is "lost or "superseded" the row should be moved to worksheet "Lost".

    I would be grateful for any guidance on this one.

    Many thanks,

    DC

    File is attached.
    Attached Files Attached Files

  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: Moving rows into a new worksheet if colour or cell = a specified colour or term

    Try this on for size:

    Option Explicit
    
    Sub TransferRows()
    'JBeaucaire (7/13/2009)
    Dim LR As Long, LC As Long, NR As Long, i As Long
        
        If Not ActiveSheet.Name Like "Q*" Then
            MsgBox "Please activate select correct data sheet before running macro."
            Exit Sub
        End If
    
    LR = Range("A" & Rows.Count).End(xlUp).Row
    
        For i = LR To 4 Step -1
            Select Case LCase(Cells(i, "P"))
                Case "won"
                    If Cells(i, "P").Interior.ColorIndex = 10 Then
                        NR = Sheets("Won").Range("A" & Rows.Count).End(xlUp).Row + 1
                        Rows(i).Copy Sheets("Won").Range("A" & NR)
                        Rows(i).Delete (xlShiftUp)
                    End If
                Case "lost", "superseded"
                    If Cells(i, "P").Interior.ColorIndex = 3 Then
                        NR = Sheets("Lost").Range("A" & Rows.Count).End(xlUp).Row + 1
                        Rows(i).Copy Sheets("Lost").Range("A" & NR)
                        Rows(i).Delete (xlShiftUp)
                    End If
            End Select
        Next i
    End Sub
    Also, for some reason you had separate LISTS active in each column of your Q1 sheet, and that should really be just ONE big list so the same # of rows is active all the time, yes? Here's the data back with one LIST instead of 15.

    Also, changed the Rolling Total formula to simply sum the whole column.
    ===========

    How to add the macro to your sheet:

    1. Open up your workbook
    2. Get into VB Editor (Press Alt+F11)
    3. Insert a new module (Insert > Module)
    4. Copy and Paste in your code (given above)
    5. Get out of VBA (Press Alt+Q)
    6. Save your sheet

    The macro is installed and ready to use. Press Alt-F8 and select it from the macro list.
    Attached Files Attached Files
    Last edited by JBeaucaire; 07-13-2009 at 10:08 AM. Reason: Posted wrong macro, oops.
    _________________
    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
    Registered User
    Join Date
    07-13-2009
    Location
    Cheltenham, England
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Moving rows into a new worksheet if colour or cell = a specified colour or term

    The row does not seem to move if “won” but not green.* I would like the row to move if it is green AND/OR marked as “won”.
    *
    The row does not seem to move if “lost” or “superseded” but not red.* I would like the row to move if it is red AND/OR marked as “lost” or “superseded”
    *
    Can I also add rules for entry into particular columns:
    *
    I would like excel to return “invalid entry” if in the CONTACT NUMBER Column the phone number format is not entered with a country code i.e. “+44123456”
    *
    Similarly with the MARGIN Column, this figure should trigger a warning “LOW MARGIN ALERT” if under 40%.
    *
    The PROBABILITY Column should only return figures of 25%, 50%, 75% or 100%.
    *
    CALL TO ACTION Column, MUST be completed.
    *
    Is it then possible to automatically fill in the table on worksheet “09-10 Total”? I am looking for total number of valid and quote wins quotes within the month into row 2, in this example it would return 6 valid and 2 won TOTAL of 8 for July.
    *
    For rows 3 and 4 this would return the values from column “J” or just the rolling total from the current month for row “4”.**
    And the carried fwd value from column “J” or just the rolling total for row “3”.
    *
    The estimate and intake figure will be updated manually.
    *
    One other snag – is it possible to ensure that all CELLS, ROWS and COLUMNS remain a consistent size throughout the document?
    *
    Attached Files Attached Files
    Last edited by davecheng; 07-14-2009 at 05:47 PM.

  4. #4
    Registered User
    Join Date
    07-13-2009
    Location
    Cheltenham, England
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Moving rows into a new worksheet if colour or cell = a specified colour or term

    Quote Originally Posted by JBeaucaire View Post
    Try this on for size:

    Option Explicit
    
    Sub TransferRows()
    'JBeaucaire (7/13/2009)
    Dim LR As Long, LC As Long, NR As Long, i As Long
        
        If Not ActiveSheet.Name Like "Q*" Then
            MsgBox "Please activate select correct data sheet before running macro."
            Exit Sub
        End If
    
    LR = Range("A" & Rows.Count).End(xlUp).Row
    
        For i = LR To 4 Step -1
            Select Case LCase(Cells(i, "P"))
                Case "won"
                    If Cells(i, "P").Interior.ColorIndex = 10 Then
                        NR = Sheets("Won").Range("A" & Rows.Count).End(xlUp).Row + 1
                        Rows(i).Copy Sheets("Won").Range("A" & NR)
                        Rows(i).Delete (xlShiftUp)
                    End If
                Case "lost", "superseded"
                    If Cells(i, "P").Interior.ColorIndex = 3 Then
                        NR = Sheets("Lost").Range("A" & Rows.Count).End(xlUp).Row + 1
                        Rows(i).Copy Sheets("Lost").Range("A" & NR)
                        Rows(i).Delete (xlShiftUp)
                    End If
            End Select
        Next i
    End Sub
    Also, for some reason you had separate LISTS active in each column of your Q1 sheet, and that should really be just ONE big list so the same # of rows is active all the time, yes? Here's the data back with one LIST instead of 15.

    Also, changed the Rolling Total formula to simply sum the whole column.
    ===========

    How to add the macro to your sheet:

    1. Open up your workbook
    2. Get into VB Editor (Press Alt+F11)
    3. Insert a new module (Insert > Module)
    4. Copy and Paste in your code (given above)
    5. Get out of VBA (Press Alt+Q)
    6. Save your sheet

    The macro is installed and ready to use. Press Alt-F8 and select it from the macro list.
    Thank you very much for your help - I hav a couple of other small tweaks - can you help again please?

+ 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