2017-08-30 73 views
0

對不起,我對此感到陌生。請原諒任何無知。如何在Microsoft Excel中更改特定字符的顏色

我有一個包含在B,d,F和H.

這些字符的範圍從0-9和A-Z(二者上殼體和下殼體)的列數隨機字符的表。

我想找到每個列中的所有相似字符並更改它們的顏色。我想對每個可用字符重複此操作。有人可以幫幫我嗎?

我在前面發現了this link,這與我正在嘗試做的非常接近。

這是受訪者表示會工作的代碼。

Sub Test1() 
Application.ScreenUpdating = False 
Dim cell As Range, i As Integer, cellVal As String 
With Columns(1) 
.SpecialCells(2, 3).Font.ColorIndex = 1 
For Each cell In .SpecialCells(2, 3) 
cellVal = cell.Text 
For i = Len(cellVal) To 2 Step -1 
If cell.Characters(i, 1).Text = "s" Then cell.Characters(i, 
1).Font.ColorIndex = 3 
Next i 
Next cell 
End With 
Application.ScreenUpdating = True 
End Sub 

當我嘗試這是犯規影響我的表中的字符。

感謝您的幫助。

+0

您的值是硬編碼還是公式的結果?這不適用於公式。 –

+0

值很難 - 我自己打字。 –

+0

這些值有多長?我不認爲這適用於長度超過255個字符的文字。 –

回答

0

上面的代碼只會將第一個字符後的第一列中的值更改爲紅色,如果它是「s」。 我改變了上面的代碼,我覺得這是更你想要什麼:

Sub ChangeCellCharacterColors() 
Dim cell As Range, i As Integer, cellVal As String 
For Each cell In Worksheets("Sheet1").Range("A1:D10").Cells 'Enter sheet name and range of cells to iterate through 
cellVal = cell.Text 
    For i = 1 To Len(cellVal) 
     If cell.Characters(i, 1).Text = "B" Then cell.Characters(i, 1).Font.ColorIndex = 4 'Identify character "B" and color index 4(green) 
     If cell.Characters(i, 1).Text = "D" Then cell.Characters(i, 1).Font.ColorIndex = 2 
     If cell.Characters(i, 1).Text = "F" Then cell.Characters(i, 1).Font.ColorIndex = 3 
     If cell.Characters(i, 1).Text = "H" Then cell.Characters(i, 1).Font.ColorIndex = 5 
    Next i 
Next cell 
End Sub 

參考老答案:

您可以創建其顏色基於包含在特定文本的單元格顯示規則細胞。

選擇要格式化

首頁 - >條件formatting->新規則>格式只包含細胞的細胞。

然後將「單元格值」更改爲「特定文本」。

'Format ...'按鈕來更改顏色填充

+0

感謝您的快速響應。我正在使用Excel '10這些方向仍然有效嗎?我試圖跟着他們,但當我點擊條件格式,然後嘗試查找顏色比例時,我迷路了。 –

+0

哦,我很抱歉,我跟着方向..過了一天。 –

+0

我可能沒有很好地解釋我的問題。每個單元格都有自己的獨特字符集,範圍從0-9 A-Z(包括小寫字母)。我想找到位於每個單元格中的所有「A」,並將它們變成紅色。然後我想找到所有的「B」並改變他們不同的顏色。如此等等,直到所有角色都被覆蓋。再次感謝。 –