【发布时间】:2017-08-07 12:43:09
【问题描述】:
我需要搜索包含多张工作表的整个 Excel workbook
可能出现在多列中的文本字符串
(比如说在 A 列到 J 列的范围内)
找到文本字符串后,它会将颜色格式应用于单元格。
这可能吗,还是我必须为每张纸制定规则?
一个例子:
- 在我的
workbook中的任意位置查找字符串“信息”并将单元格设置为蓝色
我要输入多个不同的文本字符串,每个字符串都有不同的颜色格式。
有没有办法将它们全部组合在一个规则中,还是只需要让我为每个规则创建一个新规则,使用为每个文本字符串修改的相同规则?
我对 Excel 中的条件格式非常陌生,所以如果你能温柔地指导我完成每一步,我将不胜感激。
我已经搜索了 oracle 互联网并找到了这个解决方案。我需要对其进行测试,但它可能会满足我的需求。
这需要我构建一个名为 ChooseColors 的表。第一列是搜索字符串,第二列是颜色——从可用范围中挑选。 搜索区域在第二张纸上——从这张纸开始。
代码:
Sub DoColors()
Dim Picker As Variant
Dim Colors As Variant
Dim Rws As Long, j As Long
Dim i As Integer
Dim Sht As String
Dim c As Range
Dim FirstAddress
Sht = ActiveSheet.Name
'load search strings and colors into arrays
Application.Goto Reference:="ChooseColors"
ReDim Picker(1 To Selection.Rows.Count)
ReDim Colors(1 To Selection.Rows.Count)
For i = 1 To Selection.Rows.Count
Picker(i) = ActiveCell.Value
Colors(i) = ActiveCell.Offset(0, 1).Interior.ColorIndex
ActiveCell.Offset(1, 0).Select
Next i
'search the test range, changing backgrounds as required
Sheets(Sht).Activate
For i = 1 To UBound(Picker)
With Cells.SpecialCells(xlCellTypeConstants, xlTextValues)
Set c = .Find(Picker(i), LookIn:=xlValues)
If Not c Is Nothing Then
FirstAddress = c.Address
Do
c.Interior.ColorIndex = Colors(i)
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> FirstAddress
End If
End With
Next i
End Sub
【问题讨论】:
-
新条件和新颜色必须是新规则
-
您也使用 [excel-vba] 标记您的问题,因此您可以编写 vba 解决方案?
-
你肯定需要一个宏。 VBA 来拯救这里! :D
-
我不介意它的 VBA,因为工作表中已经有一些其他 VBA 解决方案并且已经启用了宏
-
编辑您的 OP 并在那里发布您的代码 - 很难在评论中阅读它...