【问题标题】:VBA, search string within a formula in excelVBA,在excel中的公式中搜索字符串
【发布时间】:2016-10-26 10:58:03
【问题描述】:

是否可以使用 vba 搜索公式中的特定文本?例如:我有一堆 index(array match(array,"criteria"0),0) 和其他求和公式。我想用“索引”搜索公式并更改单元格颜色。

到目前为止,我已经编写了以下代码:

For Each cell In ActiveSheet.UsedRange 'color cells having formulas
    If cell.HasFormula Then 
        Find = "*index*" 
        cell.Font.Color = indexcolor
    End if
Next cell

【问题讨论】:

  • 是的,有可能。
  • 请看how to ask
  • 您可以使用Range.Find 方法查看公式,然后您可以使用c.Interior.Color = vbRed 突出显示单元格。上面的链接甚至包括你需要的 VBA 代码(微软为你预先编写的)。

标签: string excel vba search text


【解决方案1】:

怎么样:

Sub LookinForDory()
    Dim r As Range, s As String
    For Each r In ActiveSheet.UsedRange.Cells.SpecialCells(xlCellTypeFormulas)
        s = LCase(r.Formula)
        If InStr(1, s, "index") > 0 Then
            r.Interior.ColorIndex = 27
        End If
    Next r
End Sub

【讨论】:

    【解决方案2】:
    Sub Changecellcolor()
    
    Dim formulaColor As Long
    Dim cell As Range
    
    LinkedCells = RGB(Red:=0, Green:=0, Blue:=255)
    
        For Each cell In ActiveSheet.UsedRange.SpecialCells(xlCellTypeFormulas)
        If InStr(1, cell.Formula, "index") > 0 Then
        cell.Font.Color = LinkedCells
        End If
    

    结束子

    【讨论】:

      猜你喜欢
      • 2018-09-14
      • 2021-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-04
      • 2017-09-08
      相关资源
      最近更新 更多