2014-05-25 214 views
1

没有人知道如何更改电子表格中单元格的内容,具体取决于在同一单元格中发现的内容,然后使用VBA更改颜色方案更改单元格的内容,具体取决于单元格中的内容

例如

单元格值= N/A#

新的单元值将是=没有以前的报告

配色方案=黑色&波尔黄色背景

或者

单元格值=零或细胞d文字无关,在这样的空白

新的单元值将是=没有更新提供了以前报告

配色方案=白色&红色背景上的粗体文本

还有其他单元格值,这些值将保持不变。

预先感谢任何帮助只要它是最理解

http://www.mrexcel.com/forum/excel-questions/780048-how-do-you-change-contents-cell-depending-what-already-cell.html

回答

1

选择单元格,并运行此:

Sub repair() 
    Dim r As Range 
    For Each r In Selection 
     If r.Text = "#N/A" Then 
      r.Value = "Not On Previous Report" 
      r.Interior.ColorIndex = 27 
      r.Font.FontStyle = "Bold" 
     End If 
     If r.Value = "" Or r.Value = 0 Then 
      r.Value = "No Update Provided On Previous Report" 
      r.Interior.ColorIndex = 3 
      r.Font.FontStyle = "Bold" 
      r.Font.ColorIndex = 2 
     End If 
    Next r 
End Sub 
+0

作为参考,Excel公式'IFERROR'可以如果使用的话颜色变化不是要求的一部分。 – RubberDuck

+1

@ ckuhn203你是对的! –

相关问题