自从我使用 Excel 以来已经有 6 年了,我有点生疏了。这是我的场景:
我正在将问题列表导出到 Excel。我需要能够区分单元格中关联的链接号(多个值)。例如,我有两列,
Key = 票证号码
关联问题 = 关联的 key
我需要一个语句来扫描“键”列并在“链接问题”列中找到匹配项。然后,一旦找到匹配,匹配文本将采用键的字体颜色。
事情变得复杂的是“链接问题”列的每个单元格可能看起来像 iss-3913、iss-3923、iss-1649。因此本质上扫描是为了字符串内的匹配。如有任何帮助,我们将不胜感激。
最佳答案
抱歉,我现在没有时间完成此操作,但是 w这样的内容是否会有所帮助可能为第一列中的每个单元格提供一个循环?
编辑:现已完成,第二次编辑更新到 B5 和 Z5,编辑 3 个修复了列引用的错误,并更新为使用变量来分配要查看的列。
Sub colortext()
start_row = 5
key_col = 2
linked_col = 26
i = start_row 'start on row one
Do While Not IsEmpty(Cells(i, key_col)) 'Do until empty cell
o = start_row 'start with row one for second column
Do While Not IsEmpty(Cells(o, linked_col)) 'Do until empty cell
If Not InStr(1, Cells(o, linked_col), Cells(i, key_col)) = 0 Then 'if cell contents found in cell
With Cells(o, linked_col).Characters(Start:=InStr(1, Cells(o, linked_col), Cells(i, key_col)), Length:=Len(Cells(i, key_col))).Font
.Color = Cells(i, key_col).Font.Color 'change color of this part of the cell
End With
End If
o = o + 1 'increment the cell in second column
Loop
i = i + 1 'increment the cell in the first column
Loop
End Sub
或者也许
类似这样的吗?
Excel VBA: change font color for specific char in a cell range
关于string - 搜索文本字符串以查找匹配项并更改字体颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18000122/