'这段代码的目的其实也是无意中想到notepad++对代码的自动颜色区分的功能,想了一下如果把这个功能加到平时excel的计算书中去,应该在可读性和'检查的时候也更方便;沿袭的是当初excel中剔除汉字代码的思路,代码作用还是成功,

'功能1)自动将计算式中注释的正文标注为其他颜色,对参与计算运算符号进行指定颜色区分,对数字内容设为默认颜色,便于区分开来;

'功能2)自动将小计的行格式进行统一化

'代码段:

' ColorText Start------------
'代码流程记录:首先对小计进行字体格式处理;然后再对计算公式中的字符进行颜色替换(包括有些单行含公式的小计)
'代码流程记录:先处理汉字,再处理运算符。
For ix = 4 To ak - 1
        '格式化小计区域-----------(start)
            If Cells(ix, "b") <> "" Then
                   With Range("a" & ix & ":g" & ix)
                       .Interior.ColorIndex = 44
                       '.Font.Bold = 1
                       .Font.ColorIndex = 3
                   End With
            End If
        '格式化小计区域-----------(end)
         
         
        If Cells(ix, "d") <> "" Then
                  len1 = Len(Cells(ix, "d"))
                  str1 = Cells(ix, "d")
                  Range("d" & ix).Select
                  ActiveCell.FormulaR1C1 = str1 '该代码是将字符str1同时作为单元格自身内容来同步处理,str1只用于位置判断用
            
                    For j = 1 To len1
                    
                              If Asc(Mid(str1, j, 1)) <= 0 Then
                                    ActiveCell.Characters(Start:=j, Length:=1).Font.ColorIndex = 23
                              Else
                                    ActiveCell.Characters(Start:=j, Length:=1).Font.ColorIndex = xlAutomatic
                              End If
                      
                              If Mid(str1, j, 1) = "(" Or Mid(str1, j, 1) = "(" Or Mid(str1, j, 1) = ")" Or Mid(str1, j, 1) = ")" Then
                                    ActiveCell.Characters(Start:=j, Length:=1).Font.ColorIndex = 7
                              ElseIf Mid(str1, j, 1) = "+" Or Mid(str1, j, 1) = "-" Then
                                    ActiveCell.Characters(Start:=j, Length:=1).Font.ColorIndex = 46
                              ElseIf Mid(str1, j, 1) = "*" Or Mid(str1, j, 1) = "/" Or Mid(str1, j, 1) = "×" Or Mid(str1, j, 1) = "÷" Then
                                    ActiveCell.Characters(Start:=j, Length:=1).Font.ColorIndex = 10
                              End If
                  
                    Next j
         
        End If
Next ix
' ColorText End------------