【发布时间】:2018-06-18 18:23:13
【问题描述】:
我唯一需要修改的是下面列出的公式。我已修改代码以将条件格式应用于我的范围内介于两个值(输入值 1 和 2)之间的任何单元格值。例如 - 如果我正在搜索介于 20,000 和 50,000 之间的任何单元格值,它会将这些单元格的字体颜色更改为红色和粗体。编码的下一部分使用该公式对 G 列中的单元格应用条件格式。
我能否以某种方式修改下面的公式,以便在指定范围内找到任何大于或等于输入值 1 但小于或等于输入值 2 的值?该公式目前仅搜索值 1 的确切值。
=ISNUMBER(SEARCH(" & Chr(34) & Value1 & Chr(34) & ",""&AB1&"",""&AG1&"",""&AL1&"",""&AQ1))"
下面我已经剪切并粘贴了我的代码
Sub Between_Values()
Dim Value1 As String
Dim Value2 As String
Dim myRange As Range
Dim myFormula As String
Value1 = InputBox("Between This amount (enter lowest contract amount)")
Value2 = InputBox("And This amount (enter highest contract amount)")
Set myRange = Range("G:G,AB:AB,AG:AG,AL:AL,AQ:AQ")
myRange.Cells.FormatConditions.Delete
myRange.FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, _
Formula1:="=" & Value1, Formula2:="=" & Value2
myRange.FormatConditions(myRange.FormatConditions.Count).SetFirstPriority
With myRange.FormatConditions(1).Font
.Italic = False
.Bold = True
.Color = 255
.TintAndShade = 0
End With
myFormula = "=ISNUMBER(SEARCH(" & Chr(34) & Value1 & Chr(34) & ",""&AB1&"",""&AG1&"",""&AL1&"",""&AQ1))"
Columns("G:G").FormatConditions.Add Type:=xlExpression, Formula1:=myFormula
Columns("G:G").FormatConditions(Columns("G:G").FormatConditions.Count).SetFirstPriority
With Columns("G:G").FormatConditions(1).Font
.Bold = True
.Color = 255
.TintAndShade = 0
End With
Columns("G:G").FormatConditions(1).StopIfTrue = False
End Sub
【问题讨论】:
标签: excel search excel-formula conditional-formatting vba