+ Reply to Thread
Results 1 to 5 of 5

in need of macro to copy a row of data to another sheet based on text color of one cell

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-12-2013
    Location
    chicago, illinois
    MS-Off Ver
    Excel 2010
    Posts
    109

    in need of macro to copy a row of data to another sheet based on text color of one cell

    Hello all. i have searched around for such code to help me but have either run into things that don't work or things that i don't quite understand. I have many rows of data. in a specific column...say, "K", i have text in the form of either "YES" or "NO" and the text is colored either red or green. Based on the text color of that one cell, i need a macro that, when my button is pushed, will copy each entire row of data based on that yes or no cell to a different sheet in my workbook. this is what i am working with tho i know it is most likely way off.

    Sub movefails()
    
    Dim c As Range
    
        'If Selection.Columns.Count > 1 Then Exit Sub
    
        For Each c In Sheets("problems").Range("K5", "K").End(xlDown)
            If c.Font.Color = vbRed Then
                c.EntireRow.Copy
                Sheets("prodfail").Select
                Cells.Offset(1, 0).Select
                
                ActiveSheet.Paste
               
            End If
        Next c
    End Sub
    thanks!
    Last edited by fredderf81; 09-20-2013 at 03:30 PM. Reason: typo

  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: in need of macro to copy a row of data to another sheet based on text color of one cel

    Hi fredder,

    I altered your code a little - see if it works now:

    Sub movefails()
    
    Dim c As Range, K As Range, wp As Worksheet
    Set wp = Sheets("problems")
    Set K = wp.Range("K5:K" & wp.Range("K" & Rows.count).End(xlUp))
       
        For Each c In K
            If c.Font.Color = vbRed Then
                c.EntireRow.Copy Sheets("prodfail").Cells.Offset(1, 0)
            End If
        Next c
    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 Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: in need of macro to copy a row of data to another sheet based on text color of one cel

    fredderf81,

    The following works for me in a test worksheet.

    Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

    
    Option Explicit
    Sub movefailsV2()
    ' stanleydgromjr, 09/20/2013
    ' http://www.excelforum.com/excel-programming-vba-macros/956607-in-need-of-macro-to-copy-a-row-of-data-to-another-sheet-based-on-text-color-of-one-cell.html
    Dim c As Range, nr As Long
    For Each c In Sheets("problems").Range("K5:K" & Cells(Rows.Count, "K").End(xlUp).Row)
      If c.Font.Color = vbRed Then
        nr = Sheets("prodfail").Range("K" & Rows.Count).End(xlUp).Offset(1).Row
        Rows(c.Row).Copy Sheets("prodfail").Range("A" & nr)
      End If
    Next c
    End Sub
    Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

    Then run the movefailsV2 macro.
    Have a great day,
    Stan

    Windows 10, Excel 2007, on a PC.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  4. #4
    Forum Contributor
    Join Date
    09-12-2013
    Location
    chicago, illinois
    MS-Off Ver
    Excel 2010
    Posts
    109

    Re: in need of macro to copy a row of data to another sheet based on text color of one cel

    thank you both for your inputs, i received an error about an object not declared...i believe...for the first batch of code. i may have messed it up =) the second one worked perfectly. thank you both again!

  5. #5
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: in need of macro to copy a row of data to another sheet based on text color of one cel

    You're welcome!

+ 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. Copy a row from one sheet to another based on the color of a cell
    By Data2link in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-31-2013, 05:36 PM
  2. Copy entire row to another sheet based on cell color
    By Marco-Kun in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-18-2013, 09:13 AM
  3. [SOLVED] Copy a row to another sheet based on cell fill color
    By swatkins1977 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-22-2012, 02:55 PM
  4. [SOLVED] Macro to Copy Data from one Sheet A to Sheet B based on value in cell on sheet A
    By scass in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-11-2012, 07:21 PM
  5. copy and paste to another sheet based in cell color
    By nat3ten in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-08-2005, 07:05 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