+ Reply to Thread
Results 1 to 4 of 4

If column A has gray fill and column B has no fill, delete that row

  1. #1
    Registered User
    Join Date
    08-08-2012
    Location
    boise
    MS-Off Ver
    Excel 2010
    Posts
    2

    If column A has gray fill and column B has no fill, delete that row

    So I have a spreadsheet with lots of excess rows of data. I need to remove these rows based on the criteria of: If column A has gray fill (RGB value 224, 224, 224) AND column B has no fill color, THEN delete the entire row (not just clear the contents). Below is the code that I have tried, but when I run the macro it does nothing. Any help as to why this is not working?

    Please Login or Register  to view this content.
    Last edited by killhuman; 10-11-2012 at 06:00 PM.

  2. #2
    Registered User
    Join Date
    08-15-2012
    Location
    Las Vegas
    MS-Off Ver
    Excel 2010
    Posts
    87

    Re: If column A has gray fill and column B has no fill, delete that row

    I assume the cells in column A have data in them. If so then you can use the following code:

    Please Login or Register  to view this content.
    One issue I think you were running into was the your code RGB(255, 255, 255) is not the same as no fill.

    If the cells in Column A don't have data then the line
    Please Login or Register  to view this content.
    will return 1 for LastRow.

    I'm not sure how to get the last highlighted cell in a range vs. the last cell with data. In this case you may have to loop through every cell in column A which might take a while. Maybe someone else has some code to get the last highlighted cell.

    I have attached a sample workbook.
    Attached Files Attached Files
    Last edited by g8r777; 10-11-2012 at 04:20 PM.

  3. #3
    Registered User
    Join Date
    08-08-2012
    Location
    boise
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: If column A has gray fill and column B has no fill, delete that row

    Thanks for the help! That code is almost perfect. The one issue is that it only deletes every other row that meets the criteria. So if there are four consecutive rows that should be deleted, only two of them get deleted. Any idea why?

  4. #4
    Registered User
    Join Date
    08-15-2012
    Location
    Las Vegas
    MS-Off Ver
    Excel 2010
    Posts
    87

    Re: If column A has gray fill and column B has no fill, delete that row

    Try the following code instead. I forgot that when you have code that deletes rows you need to have some way to decrement the loop. If you don't then the combination of deleting a row and then going to the next item in the loop will skip a row.

    Please Login or Register  to view this content.
    One method to overcome this is to start at the bottom and work up. That way when you delete a row you have already performed the necessary actions on the rows below so you don't care if your current row is deleted.
    Last edited by g8r777; 10-11-2012 at 05:41 PM.

+ 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