2014-05-25 212 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你是對的! –

相關問題