[英]Search text string for a match and change font color
It's been 6 years since I've worked with Excel and i'm a little bit rusty. 自从我使用Excel已有6年了,我有点生锈。 Here's my scenario: 这是我的情况:
I am exporting a list of issues to Excel. 我正在将问题列表导出到Excel。 I need to be able differentiate the associated Link numbers in a cell (mulitple values) from each other. 我需要能够区分一个单元格(多个值)中的关联链接号。 Example, i have two columns, 例如,我有两列,
Key = the number for a ticket 钥匙=机票号码
Linked Issues = The Keys associated 链接的问题=关联的密钥
I need a statement that would scan the Key column and find a match in the Linked Issues column. 我需要一条可以扫描“关键”列并在“链接的问题”列中找到匹配项的语句。 Then once the match is found the matching text will assume the font color of the Key. 然后,一旦找到匹配项,则匹配的文本将采用Key的字体颜色。
Where this get complicated is each cell of the Linked Issues column could look something like this iss-3913, iss-3923, iss-1649. 使问题变得复杂的地方是“链接的问题”列中的每个单元格看起来像是iss-3913,iss-3923,iss-1649。 So essentially the scan would be for a match within the string. 因此,实质上,扫描将是针对字符串中的匹配项。 Any help is appreciated. 任何帮助表示赞赏。
I am sorry, I don't have time to finish this right now, but w 抱歉,我现在没有时间完成此操作,但是 Would something like this help 这样的事情会有所帮助吗 with maybe a loop for each cell in the first column 第一列中的每个单元格可能都有一个循环 ? ?
Edit : Finished now, second edit to update to B5 and Z5, edit 3 fixed goof with column reference and updated to use variables to assign what column to look in. 编辑 :现在完成,第二次编辑以更新为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
or maybe 或者可能
Something like this? 像这样吗
Excel VBA: change font color for specific char in a cell range Excel VBA:更改单元格区域中特定字符的字体颜色
This is an old post but I thought I would provide my work around to the conditional formating issue I was having. 这是一篇旧文章,但是我想我将围绕我遇到的条件格式问题提供我的工作。
Sub colorkey()
start_row = 5
key_col = 2
flag_col = 4
i = start_row 'start on row one
Do While Not IsEmpty(Cells(i, key_col)) 'Do until empty cell
Tval = Cells(i, flag_col).Value
Select Case Tval
Case "Requirement"
'cval = green
cVal = 10
Case "New Feature"
'cval = orange
cVal = 46
Case "Test"
'cval = lt blue
cVal = 28
Case "Epic"
'cval = maroon
cVal = 30
Case "Story"
'cval = dk blue
cVal = 49
Case "Theme"
'cval = grey
cVal = 48
Case "Bug"
'cval = red
cVal = 3
Case "NOT MAPPED"
'cval = Maroon
cVal = 1
End Select
Cells(i, key_col).Font.ColorIndex = cVal
i = i + 1 'increment the cell in the first column
Loop
End Sub
Sub colorlinked()
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
MsgBox "Finished Scanning"
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.