+ Reply to Thread
Results 1 to 5 of 5

Delete Row Based On Interior Colour

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    10-31-2010
    Location
    london
    MS-Off Ver
    Excel 365
    Posts
    152

    Delete Row Based On Interior Colour

    Hi could someone point me in the right direction of where I am going wrong, I want to run through column B and if the cell is coloured Red then delete that row, I have the below code which seems to run through each cell but doesn't delete the row? Any help would be much appricated


    Sub Delete()
    
    With ActiveSheet
    
    Dim LR As Long
    Dim Counter As Long
    '
    LR = .Range("B" & Rows.Count).End(xlUp).Row
    
        For Counter = LR To 2 Step -1
            With Cells(Counter, "B")
                If Cells.Interior.color = 255 Then
                    Rows(Counter).Delete Shift:=xlUp
                End If
            End With
        Next Counter
        End With
    
    End Sub

  2. #2
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Delete Row Based On Interior Colour

    Option Explicit
    
    Sub Delete()
    
        Dim LR As Long
        Dim Counter As Long
        
        Application.ScreenUpdating = False
        
        With ActiveSheet
        
        LR = .Range("B" & Rows.Count).End(xlUp).Row
        
            For Counter = LR To 2 Step -1
                With .Cells(Counter, "B")
                    If .Interior.Color = 255 Then
                        .EntireRow.Delete
                    End If
                End With
            Next Counter
        End With
            
        Application.ScreenUpdating = True
    
    End Sub
    Palmetto

    Do you know . . . ?

    You can leave feedback and add to the reputation of all who contributed a helpful response to your solution by clicking the star icon located at the left in one of their post in this thread.

  3. #3
    Forum Contributor
    Join Date
    10-31-2010
    Location
    london
    MS-Off Ver
    Excel 365
    Posts
    152

    Re: Delete Row Based On Interior Colour

    Ok its still not quite working, ive added the line before it aswell, im adding a conditional format to change the cell color to 255, then it wont delete them, if I manually go in and change the colour to 255 then the code works, so it seems that the condition format is not changing the color correctly??? im really confused now.



     Range("B2").Select
        Range(Selection, Selection.End(xlDown)).Select
        Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$F2=TRUE"
        Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
        With Selection.FormatConditions(1).Interior
            .PatternColorIndex = xlAutomatic
            .color = 255
        End With
        Selection.FormatConditions(1).StopIfTrue = False
    With ActiveSheet
    
    
        For Counter = LR To 2 Step -1
            With Cells(Counter, "B")
                If .Interior.color = 255 Then
                    .EntireRow.Delete
                End If
            End With
        Next Counter
        End With
    
    End Sub

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644
    Use the condition you are using in rge conditional formatting to determine whether or not to delete a row.
    If posting code please use code tags, see here.

  5. #5
    Forum Contributor
    Join Date
    10-31-2010
    Location
    london
    MS-Off Ver
    Excel 365
    Posts
    152

    Re: Delete Row Based On Interior Colour

    That work perfectly, im not to sure why the other way didn't work but this is much better any way.

+ 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