+ Reply to Thread
Results 1 to 4 of 4

Macro to Delete Rows with Fill Color

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-26-2015
    Location
    Canada
    MS-Off Ver
    2013
    Posts
    248

    Macro to Delete Rows with Fill Color

    Hi,

    I found and was able to modify a macro to delete rows with specific fill color. The problem is that on any given day I could be running this on 25-100K rows and the macro is fairly slow. I was just wondering if anybody had a better option or if it is possible to "speed up" a macro.

    The code I have is:
    Sub GreyRows()
    Dim rng As Range

    Set rng = Intersect(Range("E:E"), ActiveSheet.UsedRange)

    For x = rng.Count To 1 Step -1
    If rng(x).Interior.ColorIndex = 48 Then
    rng(x).EntireRow.Delete
    End If
    Next


    End Sub


    Thanks in advance for anybody looking at this,

    Brenda

  2. #2
    Registered User
    Join Date
    10-14-2015
    Location
    Brisbane
    MS-Off Ver
    2010
    Posts
    12

    Re: Macro to Delete Rows with Fill Color

    Hi:

    You can use the filter property of excel if do not want to loop through

    Sub Test()
        Range("A1").AutoFilter
        ActiveSheet.Range("$A$1:$A$1").AutoFilter Field:=1, Criteria1:=RGB(255, 255 _
        , 0), Operator:=xlFilterCellColor
        ActiveSheet.Range("$A$1:$A$16").Offset(1, 0).SpecialCells _
        (xlCellTypeVisible).EntireRow.Delete
    End Sub
    Note: You will have to tweak the RGB and Range to suit your needs.

    Thanks

  3. #3
    Forum Contributor
    Join Date
    02-26-2015
    Location
    Canada
    MS-Off Ver
    2013
    Posts
    248

    Re: Macro to Delete Rows with Fill Color

    Hi, Nebu

    Thanks.
    Changed the code to the following but hanging up at: (xlCellTypeVisible).EntireRow.Delete



    Sub Test()
    Range("E3").AutoFilter
    ActiveSheet.Range("E:E").AutoFilter Field:=1, Criteria1:=RGB(156, 156 _
    , 156), Operator:=xlFilterCellColor
    ActiveSheet.Range("E3:E100000").Offset(2, 0).SpecialCells
    (xlCellTypeVisible).EntireRow.Delete
    End Sub

    Any ideas?

  4. #4
    Registered User
    Join Date
    10-14-2015
    Location
    Brisbane
    MS-Off Ver
    2010
    Posts
    12

    Re: Macro to Delete Rows with Fill Color

    Hi:

    I am not sure why it is hanging at your end, try the following

    At the starting of the subroutine give the following.
    Application.Calculation = xlCalculationManual
    Application.SCreenUpdating=False
    and at the end

    Application.Calculation = xlCalculationAutomatic
    Application.SCreenUpdating=True
    Thanks

+ 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. Need macro to delete rows based on the color of cell in column A
    By cindywylie in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 02-10-2014, 05:50 PM
  2. Delete Columns and rows based on cell fill color
    By JackW in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-02-2014, 01:58 PM
  3. Compare 2 worksheets, delete dupes and group by back fill color using macro
    By jousterlj in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-25-2011, 01:50 PM
  4. Delete any row WITHOUT a fill color
    By aorum in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-16-2011, 12:05 AM
  5. Macro to Fill Specific Rows and Columns with Color Based on Cell Value
    By MSmithson in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-04-2011, 09:45 PM
  6. delete rows based on fill color
    By schueyisking in forum Excel General
    Replies: 1
    Last Post: 08-25-2008, 10:28 AM
  7. Delete rows based on fill color
    By schueyisking in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-22-2008, 05:54 AM
  8. [SOLVED] [SOLVED] Macro to color fill rows?
    By Jennifer in forum Excel General
    Replies: 10
    Last Post: 03-25-2007, 10:06 AM

Tags for this Thread

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