+ Reply to Thread
Results 1 to 12 of 12

Need macro to delete rows based on the color of cell in column A

  1. #1
    Registered User
    Join Date
    08-15-2012
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    73

    Need macro to delete rows based on the color of cell in column A

    I have a spreadsheet where the color of the cells in column A represents different stages. I want to distribute this sheet as a report of all but the last stage. Can anyone help?

  2. #2
    Forum Contributor
    Join Date
    12-14-2013
    Location
    Tilburg, Nederland
    MS-Off Ver
    Excel 2010
    Posts
    256

    Re: Need macro to delete rows based on the color of cell in column A

    Provide an example wb please

  3. #3
    Registered User
    Join Date
    08-15-2012
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    73

    Re: Need macro to delete rows based on the color of cell in column A

    sample attached
    Attached Files Attached Files

  4. #4
    Forum Contributor
    Join Date
    12-14-2013
    Location
    Tilburg, Nederland
    MS-Off Ver
    Excel 2010
    Posts
    256

    Re: Need macro to delete rows based on the color of cell in column A

    What color stands for last stage?

  5. #5
    Registered User
    Join Date
    08-15-2012
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    73

    Re: Need macro to delete rows based on the color of cell in column A

    light blue. Thanks

  6. #6
    Forum Contributor
    Join Date
    12-14-2013
    Location
    Tilburg, Nederland
    MS-Off Ver
    Excel 2010
    Posts
    256

    Re: Need macro to delete rows based on the color of cell in column A

    Got it, will put the code below.
    First you must know that the light blue used has several different colors.
    Use one color for that.

    Please Login or Register  to view this content.
    If you need the color from a cell select the cell and run next macro

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    08-15-2012
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    73

    Re: Need macro to delete rows based on the color of cell in column A

    Hi Gerard,

    Im just digging myself from up under our month end closing process to take a look at this. I picked one blue shade of highlight and ran the macro. A few of the blue rows were deleted and a few were not. I ran the macro a second time and the remaining blues were deleted. Do you know why I have to run the macro twice? A copy of the macro is below and a sample spreadsheet is attached.

    Thanks so much for your help. This saves me a great amount of time.


    Sub deleteRowOnCollor()
    Dim lLR, lC As Long
    lLR = Sheets(1).Range("A" & Rows.Count).End(xlUp).Row 'Determine last row
    For lC = 3 To lLR
    Sheets(1).Cells(lC, 1).Activate
    If ActiveCell.Interior.Color = 15773696 Then 'Used index color.
    Rows(lC).Delete Shift:=xlUp 'delete row
    'Rows(lC).EntireRow.Hidden = True 'Hide row.
    End If
    Next
    End Sub
    Attached Files Attached Files

  8. #8
    Forum Contributor
    Join Date
    12-14-2013
    Location
    Tilburg, Nederland
    MS-Off Ver
    Excel 2010
    Posts
    256

    Re: Need macro to delete rows based on the color of cell in column A

    Ha tricked my self with this one....
    Because the code ran from top to bottom, in case of a match the row was deleted. This caused that the next row became active row, but the counter was increase so that row would be skipped....
    Solved it by running the check from bottom to the top of the page....
    Also added freezing screen updating during running of macro.

    Please Login or Register  to view this content.

  9. #9
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Need macro to delete rows based on the color of cell in column A

    Cindy,
    Try the attached.
    Attached Files Attached Files

  10. #10
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Need macro to delete rows based on the color of cell in column A

    Hi, Cindy,

    Your post #7 does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  11. #11
    Registered User
    Join Date
    08-15-2012
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    73

    Re: Need macro to delete rows based on the color of cell in column A

    Gerard,

    Perfect! Thanks so much for your help.

  12. #12
    Registered User
    Join Date
    08-15-2012
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    73

    Re: Need macro to delete rows based on the color of cell in column A

    Sorry for "breaking the rules". It was not intentional. I dont post often to this forum and am not aware of all the rules. Will be more careful next time.

+ 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. Macro to delete certain columns and delete rows based on time in another column
    By beepbeep27 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-12-2012, 11:47 AM
  2. Replies: 3
    Last Post: 04-19-2012, 10:45 AM
  3. Re: Delete rows based on duplicate and cell color
    By Jsin in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-15-2010, 08:38 AM
  4. Macro to delete rows based on a value in cell
    By vjboaz in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-22-2008, 01:28 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