+ Reply to Thread
Results 1 to 8 of 8

Macro to copy rows based on background color of cells within a range of columns

  1. #1
    Forum Contributor
    Join Date
    03-29-2012
    Location
    Ottawa, Ontario
    MS-Off Ver
    Excel 2013
    Posts
    104

    Macro to copy rows based on background color of cells within a range of columns

    Hello,

    I need a macro to copy rows to a new worksheet when cells in a specified range (Column A to Z) contains a specific background color (red).

    I found the below macro that work really well but it is limited to look only in column A. I have tried to modify it to look at a range of more than one column but I was not able to figure it out. How should I modify the below macro to look in column A to Z? Thank you for your time!

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro to copy rows based on background color of cells within a range of columns

    Maybe:

    Change this:

    Please Login or Register  to view this content.
    To this:

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    03-29-2012
    Location
    Ottawa, Ontario
    MS-Off Ver
    Excel 2013
    Posts
    104

    Re: Macro to copy rows based on background color of cells within a range of columns

    Hello John,

    Thanks for your quick reply. I did modify the macro as indicated but when I run it it stop at the following line:

    If wks.Range(Cells(x, 1), Cells(x, 26)).Interior.Color = RGB(255, 0, 0) Then

    And shows the following error message:

    Run time error '1004':
    Method 'Range' of object'_worksheet' failed


    I try working a little bit with that line of coding but was not able to fix it. Any ideas what maybe needed to fix it? Thanks again!

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro to copy rows based on background color of cells within a range of columns

    I was guessing and not testing. Can you provide a sample that I can work with? To attach a file, push the button with the paperclip (or scroll down to the Manage Attachments button), browse to the required file, and then push the Upload button.

  5. #5
    Forum Contributor
    Join Date
    03-29-2012
    Location
    Ottawa, Ontario
    MS-Off Ver
    Excel 2013
    Posts
    104

    Re: Macro to copy rows based on background color of cells within a range of columns

    Quote Originally Posted by JOHN H. DAVIS View Post
    I was guessing and not testing. Can you provide a sample that I can work with? To attach a file, push the button with the paperclip (or scroll down to the Manage Attachments button), browse to the required file, and then push the Upload button.
    Hello John,

    Attached is a sample file. I have included in the file the orignal macro and a 2nd one with the changes you suggested. Thank you!
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro to copy rows based on background color of cells within a range of columns

    I think I misunderstood in Post#2, does this work for you?

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    03-29-2012
    Location
    Ottawa, Ontario
    MS-Off Ver
    Excel 2013
    Posts
    104

    Re: Macro to copy rows based on background color of cells within a range of columns

    Works great, thank you for all your time and efforts. I will mark as solved.

  8. #8
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro to copy rows based on background color of cells within a range of columns

    You're welcome. Glad to help out, and thanks for the feedback.

+ 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] Color Index to sum up cells based on background color
    By jph89 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-16-2013, 03:23 PM
  2. background cell color based on number range
    By cjpref in forum Excel General
    Replies: 1
    Last Post: 09-01-2012, 09:01 AM
  3. [SOLVED] Macro to change all cells with a certain background color in another background color
    By kevinvzandvoort in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-13-2012, 11:04 AM
  4. Replies: 3
    Last Post: 05-02-2012, 09:08 AM
  5. Copy same rows based on red color cells
    By unley in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-21-2011, 05:45 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