###前提・実現したいこと
Excelで隣り合った列に入っている文字列の差分のみ、フォントの色を変更したいと考えています。
例えば以下のような表の場合はC3とD3を比較し、C3になかった文字列の色を変えるという処理がしたいです。
※[追記]文字列は一致しない想定でお願いします。
これはそもそもExcelの関数で実現できるものなのでしょうか?
マクロでしか実現できないのでしたら、その方法を教えて頂きたいです。
###試したこと
Googleなどで検索をし、以下のマクロを試したのですが想定と全く違う結果になってしまいました。
VBA
1Sub sample1() 2 Dim i As Long 3 Dim n As Integer, t As Integer, j As Integer, f As Integer 4 Dim adrs As String 5 Dim clr() 6 Dim tbl As Range 7 adrs = ActiveCell.Address(0, 0) 8 Set tbl = Application.InputBox("範囲を指定して下さい", Type:=8) 9 With tbl 10 For i = 1 To .Rows.Count 11 Range(adrs).Cells(i, 1).Font.ColorIndex = xlAutomatic 12 If .Cells(i, 1) = .Cells(i, 2) Then 13 Range(adrs) = .Cells(i, 1) 14 Else 15 f = 1 16 t = 1 17 For n = 1 To Len(.Cells(i, 2)) 18 If Mid(.Cells(i, 1), n, 1) = Mid(.Cells(i, 2), t, 1) Then 19 Range(adrs).Cells(i, 1) = Range(adrs).Cells(i, 1) & Mid(.Cells(i, 2), t, 1) 20 Else 21 ReDim Preserve clr(f) 22 clr(f) = t 23 Range(adrs).Cells(i, 1) = Range(adrs).Cells(i, 1) & Mid(.Cells(i, 2), t, 1) 24 f = f + 1 25 If Len(.Cells(i, 1)) < Len(.Cells(i, 2)) Then 26 n = n - 1 27 End If 28 End If 29 t = t + 1 30 If t > Len(.Cells(i, 2)) Then Exit For 31 Next n 32 For j = 1 To UBound(clr) 33 Range(adrs).Cells(i, 1).Characters(Start:=clr(j), Length:=1).Font.ColorIndex = 3 34 Next j 35 End If 36 Next i 37 End With 38 End Sub
###補足情報(言語/FW/ツール等のバージョンなど)
ExcelはMicro Office Professional Plus 2016です。
必要な補足情報などありましたら追加でお伝えします。
よろしくお願いします。

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/12/01 06:38
2017/12/01 06:41
2017/12/01 06:46
2017/12/01 06:51
2017/12/01 07:08