0
公式我有一个细胞与式如何给多发色在一个单元格,如果它包含在Excel
="Average:"& AVERAGE(C2,C6)& "Items:"& SUM(C2,C6)
我需要的“平均”的红色在该单元格。以黑色保留
公式我有一个细胞与式如何给多发色在一个单元格,如果它包含在Excel
="Average:"& AVERAGE(C2,C6)& "Items:"& SUM(C2,C6)
我需要的“平均”的红色在该单元格。以黑色保留
要使用VBA解决方案执行此操作,您仍然必须复制/粘贴特殊值>,因为如果该单元格是公式,您不能仅着色单元格的某些字符。
的收官手动步骤进入VBA子程序,我们将有:
(假设你的公式为D1),它看起来像:
Sub avgSumColor()
Dim rngFormulaCell As Range, rngValueCell As Range
Dim itemStart As Integer, itemLength As Integer
'Set the cell with the formula and the cell where we'll put the value
Set rngFormulaCell = Sheet1.Range("D1")
Set rngValueCell = Sheet1.Range("D2")
'Copy/Paste special (just set the value of the valuecell to the value of the formulacell)
rngValueCell.Value = rngFormulaCell.Value
'Figure out where "Item:<number>" starts and
' how many characters long it is
itemStart = InStr(1, rngValueCell.Value, "Items")
itemLength = Len(rngValueCell.Value) + 1 - itemStart
'set the first bit up to the text "Item:<number>" to red
rngValueCell.Characters(1, itemStart).Font.Color = RGB(255, 0, 0)
'set the last bit containing "Item:<number>" to black
rngValueCell.Characters(itemStart, itemLength).Font.Color = RGB(1, 1, 1)
End Sub
你不能。您必须将公式替换为值,或者只使用两个单元格。 – Rory