另一种方法是使用VBA代码。例如,当A1单元格的值大于3时,字体颜色将变为红色。可以编写如下VBA代码:Sub 字体红色()If Range("A1").Value > 3 Then Range("A1").Font.ColorIndex = 3 End If End Sub 这段代码需要在Excel的VBA编辑器中运行。在“开发工具”选项卡中点击“Visual Basic”,在...
A10,格式-条件格式-单元格数值的介于改为大于,数值填写3\x0d\x0a格式设置字体为红色\x0d\x0a确定确定 \x0d\x0a2)vba也可以,比如:如果A1>3那么就显示字体为红色\x0d\x0aSub 字体红色()\x0d\x0aIf [A1] > 3 Then\x0d\x0a [A1].Font.ColorIndex = 3\x0d\x0aEnd If...
If iCell.Interior.Color = Col.Interior.Color Then SumByBGColor = SumByBGColor + Application.WorksheetFunction.Sum(iCell) End If Next End Function Function CountByFontColor(Col As Range, CountRange As Range) '根据字体颜色色计数 Application.Volatile Dim iCell As Range CountByFontColor = 0 For ...
ICellStyle newStyle = styleCache[sourceCell.CellStyle]; //读取原文件的字体,此时白色字体颜色值(IFont.Color)与黑色字体颜色值一样,数值为8 IFont srcFont = sourceCell.CellStyle.GetFont(wBooks[fromBookIndex]); //同样复制创建IFont Cache IFont newFont = fontCache[srcFont]; if (newStyle == nu...
2 选择【sheet1】,右击,选择【插入】,选择【模块】3 写入代码Function SumByFontColorAndBGColor(Col As Range, SumRange As Range) '根据字体颜色及背景颜色求和Application.VolatileDim iCell As RangeSumByFontColorAndBGColor = 0For Each iCell In SumRange If iCell.Font.Color = Col.Font.Color...
A10区域中的值>3字体颜色就是红色,那么:选中A1:A10,格式-条件格式-单元格数值的介于改为大于,数值填写3格式设置字体为红色确定。2、确定 2)vba也可以,比如:如果A1>3那么就显示字体为红色Sub 字体红色()If [A1] > 3 Then [A1].Font.ColorIndex = 3End IfEnd Sub。
若希望通过其他函数改变单元格字体颜色,可以使用VBA宏。例如,编写如下代码:Sub ColorText()If Range("A1").Value > 0 ThenRange("A1").Font.Color = vbRedElseRange("A1").Font.Color = vbBlueEnd IfEnd Sub 此VBA宏会在单元格A1的值大于0时将其字体颜色设为红色,否则设为蓝色。将此代码...
If xRgD Is Nothing Then Exit Sub xRows = xRg.Rows.Count Set xRg = xRg(1) xNum = 0 For I = 1 To xRows If xRg.Offset(I - 1, 0).Font.ColorIndex = xRgS.Font.ColorIndex Then If xRg.Offset(I - 1, 0).Value = xRgS.Value Then xNum = xNum + 1 End If End If Next...
Function FontColorisRed(Rng As Range) Updateby ExtendOffice Application.Volatile If Rng.Font.ColorIndex = 3 Then FontColorisRed = "Fail" Else FontColorisRed = "Pass" End If End Function Copy 备注: 上述代码中,如果字体颜色为红色,则返回文本“失败”,如果不是红色,则返回文本“通过”。 您可以...
7).Value '取得数据 If t = 100 ThenSheets(1).Cells(i, 7).SelectSelection.Font.ColorIndex = 3End IfIf t = 300 ThenSheets(1).Cells(i, 7).SelectSelection.Font.ColorIndex = 5End IfIf t = 900 ThenSheets(1).Cells(i, 7).SelectSelection.Font.ColorIndex = 4End If NextE...