yuye1987 发表于 2014-12-28 12:03
额,那如果A列和B列的数据调过来,比如A1=01234567,如果在B1中输入123,那么A1中的数据123就自动变红色, ...
Sub dome()
Dim ar() As String, str As String, i As Long, x As Long, y As Long
For i = 1 To Cells(Rows.Count, 1).End(3).Row '循环结构,从第一行循环到最后一个非空单元格所在的行
str = Cells(i, 1) '变量str等于b列的文本,比如b1,b2..循环嘛
ReDim ar(Len(str)) '重新定义数组ar的长度等于变量str的字符数
For x = 1 To Len(str) '循环这个字符串
ar(x) = Mid(str, x, 1) '把每个数字装入数组
Next
For y = 1 To UBound(ar) '循环这个数组
If InStr(Cells(i, 2), ar(y)) Then '如果数字在A列中出现,就执行下面的语句
With Cells(i, 1).Characters(Start:=y, Length:=1).Font '满足条件的数字,设置红色
.ColorIndex = 3
End With
End If
Next
Next
End Sub