【发布时间】:2018-12-12 03:22:28
【问题描述】:
我正在尝试突出显示工作表单元格中包含相同红色字符串的两列中的单元格,然后删除包含具有两个红色单元格的行的所有行。
这是我到目前为止提出的。第一阶段有效,但后来我尝试比较两个单元格的颜色,但没有成功。
Option Explicit
Sub Macro1()
Dim WhatFor As String
WhatFor = InputBox("Enter your search word to highlight", "Search Criteria")
If WhatFor = Empty Then Exit Sub
Range("A1").Select
Selection.CurrentRegion.Select
Selection.FormatConditions.Add Type:=xlTextString, String:=WhatFor, _
TextOperator:=xlContains
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Color = -16383844
.TintAndShade = 0
End With
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 13551615
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
End Sub
Sub Macro2()
Dim i As Integer
Dim cell As Range
cell = ActiveWorkbook.ActiveSheet.Range
i = 1
Do While Cells("A, i").Value <> ""
If cell("A, i").Interior And cell("F, i").Interior = 13551615 Then:
Rows(i).EntireRow.Delete
End If
i = i + 1
Loop
End Sub
【问题讨论】:
-
给单元格着色完全没有意义?只需删除行
-
您可能是对的,但是比较字符串的两个部分对我来说太复杂了。这些值实际上不是“相等”,但大多数时候“相似”。
-
您是说删除行是在同一行中的不同单元格中多次找到指定字符串,并且该字符串在哪里匹配忽略大小写?它们作为单独的字符串存在,而不是较长字符串中的子字符串?字符串是单元格中唯一的项目吗?
-
这告诉我你没有用你的代码为单元格着色。 ... 那么细胞是如何着色的呢?
-
@jsotola
Macro1代码正在为包含所需字符串(即Like "*" & WhatFor & "*")的单元格设置条件格式。