lundi 12 juin 2017

Visual Basic If Statements using Color

Option Explicit

Sub deleteRows14()
Dim xrow As Long, xcol As Long, rcell As Range

xrow = 1
xcol = 2

Do Until Cells(xrow, xcol).Value = ""
Cells(xrow, xcol).Select
    If Cells(xrow, xcol).Value <> "" Then
        Selection.FormatConditions.Add Type:=xlTextString, String:="**/**/14", _
        TextOperator:=xlContains
        With Selection.FormatConditions(1).Font
            .Color = RGB(0, 255, 0)
            .TintAndShade = 0
        End With
        If Cells(xrow, xcol).Font.Color = RGB(0, 255, 0) Then
            Selection.EntireRow.Delete
        End If


    End If
xrow = xrow + 1
Loop

Hey guys, I am trying to delete values in a column that have certain dates. I came up with this code using conditional formatting to turn certain cells a certain color, and then loop through again and delete the cells that are that certain color. I am an amateur, if you couldn't tell.

Anyway, that second If statement "If Cells(xrow, xcol).Font.Color = RGB(0, 255, 0) Then" won't register as true; I can't get any rows to delete. How can I fix that line?

Aucun commentaire:

Enregistrer un commentaire