excel - 删除带有条件格式为红色的单元格的列
问题描述
我计划对第 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
解决方案
Using the below code you can scrape 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
推荐阅读
- ios - 如何创建可自定义的应用程序图标 Swift
- android - 如何解决警告 - 对于 Android 11 中不可用的 Google 地图版本 1
- javascript - Javascript - 开始文本输入时只读
- php - jQuery将dict附加到html,如何从1插入一个自动递增的id
- android - 如何向 Azure Bot 发送短信?
- python - 网页抓取问题 - 在页面源中看不到数据
- python-3.x - 如何在熊猫数据框中查找缺失的索引值?
- amazon-web-services - 如果在 terraform 中未指定提供程序版本约束并且涉及重大更改,会发生什么情况
- vue.js - 使用自定义主机名时,热重载不适用于 Vue CLI 项目
- sql - SQL Server 阻止更新列(插入时数据库设置的 datetime2 列值)