在财务模型中着色细胞的宏

时间:2017-12-26 14:12:24

标签: excel-vba vba excel

我有一个用于根据类型更改单元格字体颜色的宏。代码看起来像这样

Sub ModelColoring()

Dim cell As Range, constantCell As Range, formulaCells As Range
Dim cellFormula As String

With Selection
On Error Resume Next
    Set constantCell = .SpecialCells(xlCellTypeConstants, xlNumbers)
    Set formulaCells = .SpecialCells(xlCellTypeFormulas, 21)
On Error GoTo 0
End With


If Not constantCell Is Nothing Then
    constantCell.Font.Color = vbBlue
End If

If Not formulaCells Is Nothing Then
For Each cell In formulaCells
    cellFormula = cell.Formula

    If cellFormula Like "*.xls*]*!*" Then
        cell.Font.Color = RGB(0, 176, 80)
    ElseIf cellFormula Like "*!*" _
    And Not cellFormula Like "*\**" _
    And Not cellFormula Like "*+*" _
    And Not cellFormula Like "*-*" _
    And Not cellFormula Like "*/*" _
    And Not cellFormula Like "*^*" _
    And Not cellFormula Like "*%*" _
    And Not cellFormula Like "*>*" _
    And Not cellFormula Like "*<*" _
    And Not cellFormula Like "*=<*" _
    And Not cellFormula Like "*=>*" _
    And Not cellFormula Like "*<>*" _
    And Not cellFormula Like "*&*" Then
        cell.Font.Color = vbRed
    Else
    cell.Font.Color = vbBlack
    End If
Next cell
End If

End Sub

我遇到了这条线的问题

And Not cellFormula Like "*\**"

基本上我希望所有具有常量的单元格都有一种字体颜色,那些执行计算的单元格具有另一种字体颜色,以及那些从另一个图纸中获取其值的单元格。但是,由于某些原因,上面提到的行似乎没有识别乘法符号*并且使用来自其他工作表的值的单元格并将它们相乘,就好像它们只是从另一个工作表中派生一样(即vbRed而不是黑色)。

0 个答案:

没有答案
相关问题