【发布时间】:2019-07-09 21:59:27
【问题描述】:
我计划对第 18 行中的单元格进行条件格式设置,然后清除带有红色单元格的列。
当我用红色填充单元格时,此代码会删除列,但在使用条件格式时不会。
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
【问题讨论】:
-
Cells(18, iCntr).DISPLAYFORMAT.Interior.Color -
您的条件格式规则正在使用某种逻辑来突出显示红色单元格,因此只需在此处使用完全相同的逻辑。您正在使用条件格式作为中间人。跳过中间人,在 VBA 中编写你的逻辑