+ Reply to Thread
Results 1 to 11 of 11

Deleting highlighted cells within four columns of data - VBA?

Hybrid View

  1. #1
    Registered User
    Join Date
    02-18-2015
    Location
    Flower Mound, TX
    MS-Off Ver
    2013
    Posts
    32

    Deleting highlighted cells within four columns of data - VBA?

    Hi Excel Masters,

    I'm looking for some code that allows me to delete cells within a given range that are conditionally formatted (they are highlighted yellow).

    There are 4 columns (A:D) and there is 100,000 rows of data.

    Does anyone know of a solution for this?

    Thanks in advance!

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,290

    Re: Deleting highlighted cells within four columns of data - VBA?

    You can filter on cell colour and select and delete the visible cells. You don't necessarily need VBA if it is a one off or infrequent task.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    02-18-2015
    Location
    Flower Mound, TX
    MS-Off Ver
    2013
    Posts
    32

    Re: Deleting highlighted cells within four columns of data - VBA?

    Hi TMS,

    Whenever I try to filter the data, my version of Excel locks up. I think it may a result of how much data I'm trying to select as the CF has been applied to almost all of the 100000 rows... What you're recommending is a custom sort from the filter option, correct?

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,290

    Re: Deleting highlighted cells within four columns of data - VBA?

    You could try setting calculation to manual before filtering.

  5. #5
    Registered User
    Join Date
    02-18-2015
    Location
    Flower Mound, TX
    MS-Off Ver
    2013
    Posts
    32

    Re: Deleting highlighted cells within four columns of data - VBA?

    The cells are no longer conditionally formatted, so I'm not sure if that helps or not, but they are now simply highlighted yellow.

  6. #6
    Registered User
    Join Date
    02-18-2015
    Location
    Flower Mound, TX
    MS-Off Ver
    2013
    Posts
    32

    Re: Deleting highlighted cells within four columns of data - VBA?

    Sub sbDelete_Rows_Based_On_Cell_Color()
    Dim lRow As Long
    Dim iCntr As Long
    lRow = 24478
    For iCntr = lRow To 1 Step -1
    If Cells(iCntr, 1).Interior.ColorIndex = 6 Then ‘6 = Yellow
    Rows(iCntr).Delete
    
    End If
    
    Next
    End Sub
    I feel like I'm really close with the above code, but I keep getting a Compile error: End if without block if

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,290

    Re: Deleting highlighted cells within four columns of data - VBA?

    It's this:
    Then ‘6 = Yellow
    The ‘ should be a ' (single quote)

    Option Explicit
    
    Sub sbDelete_Rows_Based_On_Cell_Color()
    
    Dim lRow As Long
    Dim iCntr As Long
    
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    
    'lRow = 24478
    lRow = Range("A" & Rows.Count).End(xlUp).Row
    
    For iCntr = lRow To 1 Step -1
        If Cells(iCntr, 1).Interior.ColorIndex = 6 Then ' 6 = Yellow
            Rows(iCntr).Delete
        End If
    Next
    
    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True
    
    End Sub

  8. #8
    Registered User
    Join Date
    02-18-2015
    Location
    Flower Mound, TX
    MS-Off Ver
    2013
    Posts
    32

    Re: Deleting highlighted cells within four columns of data - VBA?

    Thanks for the response, TMS. This code works on a small range of data (20 rows), but when I try to apply it to my larger range, it doesn't work. I run the code and nothing happens. Any ideas as to why?

    Edit: I think I may have figured out why. The code works so long as there isn't and CF attached to it!
    Last edited by RedditGold; 02-21-2017 at 05:14 PM.

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,290

    Re: Deleting highlighted cells within four columns of data - VBA?

    The code works on the fill colour, which is different to any CF colour. Filtering, if it worked, works with any cell colouring.

  10. #10
    Registered User
    Join Date
    02-18-2015
    Location
    Flower Mound, TX
    MS-Off Ver
    2013
    Posts
    32

    Re: Deleting highlighted cells within four columns of data - VBA?

    Yes, so now my question becomes how do I copy my data so that it retains the formatting so I can run the macro, but still doesn't bring the CF along with it. There's 100,000 rows of data...

    It looks like you can copy tables into Word and then back into Excel without the CF, but Word locks up if it's pasting more than a handful of rows...

  11. #11
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,290

    Re: Deleting highlighted cells within four columns of data - VBA?

    Did you use a formula in CF to colour the cells? If you did, maybe you could use that in a helper column?

+ 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. Highlight cells for data entry but print workbook with no highlighted cells
    By kheino1111 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-30-2014, 06:51 AM
  2. deleting non highlighted cells after conditional formatting
    By Wanda Almeida in forum Excel General
    Replies: 2
    Last Post: 08-13-2013, 06:44 PM
  3. When deleting an email, highlighted jumps to top
    By pats12 in forum Outlook Formatting & Functions
    Replies: 0
    Last Post: 07-02-2013, 03:21 AM
  4. [SOLVED] For each row in Column A copy only corresponding Highlighted cells In other Columns
    By boorama in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-17-2013, 02:12 AM
  5. Replies: 0
    Last Post: 02-03-2012, 07:26 PM
  6. Replies: 1
    Last Post: 10-23-2009, 10:06 AM
  7. Replies: 4
    Last Post: 12-12-2008, 01:53 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