0
votes

so I made this code to delete all the columns that have a interior red cells in row 18. The code works.

The problem is it does not work when I conditional format the cells in that row. What I planned to do was conditional format the row then use the macro to quickly clear the columns with the red cells.

It works when I fill in a cell with red but not when I use conditional formatting. It seems like it should be the same red in conditional formatting.

 Sub sbDelete_Columns_Based_On_Cell_Color()
    Dim lColumn As Long
    Dim iCntr As Long

    lColumn = 50
    For iCntr = lColumn To 1 Step -1
    If Cells(18, iCntr).Interior.Color = Excel.XlRgbColor.rgbRed Then
      Columns(iCntr).Delete
    End If
    Next iCntr
    End Sub
1
Cells(18, iCntr).DISPLAYFORMAT.Interior.Coloruser11060139
Your conditional formatting rule is using some kind of logic to highlight cells red so just use that exact same logic here. You are using conditional formatting as a middle man. Skip the middle man, code your logic here in VBAurdearboy

1 Answers

1
votes

Using the below code you can scrap cell color from conditional formatting:

Option Explicit

Sub test()

    Dim Color As Long

    With ThisWorkbook.Worksheets("Sheet2")

        Color = .Range("D1").DisplayFormat.Interior.Color

    End With

End Sub