2

我使用 Excel 已经 6 年了,我有点生疏了。这是我的场景:

我正在将问题列表导出到 Excel。我需要能够将单元格(多个值)中的关联链接号彼此区分开来。例如,我有两列,

Key = 一张票的号码

关联问题 = 关联的键

我需要一个语句来扫描 Key 列并在 Linked Issues 列中找到匹配项。然后,一旦找到匹配项,匹配的文本将采用 Key 的字体颜色。

复杂的地方在于 Linked Issues 列的每个单元格可能类似于 iss-3913、iss-3923、iss-1649。所以本质上扫描将是字符串中的匹配项。任何帮助表示赞赏。

4

2 回答 2

1

对不起,我现在没有时间完成这个,但是 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:更改单元格范围内特定字符的字体颜色

于 2013-08-01T20:43:28.953 回答
1

这是一篇旧帖子,但我想我会为我遇到的条件格式问题提供我的工作。

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
于 2014-08-15T18:35:11.313 回答