在Excel中的A列中查找B列的公共字符串

时间:2015-06-03 13:55:28

标签: excel excel-formula

我想突出显示Coloumn A中coloumn B的值。 注意:B列包含A列中的文本子集。

示例: enter image description here

3 个答案:

答案 0 :(得分:1)

我能想到的最好的就是使用VBA来改变字体的颜色。

Dim row As Integer
Dim str As String
Dim index As Integer
Dim rng As Range

lastRow = ActiveSheet.Cells(ActiveSheet.Rows.Count, "A").End(xlUp).row

Set rng = Range("A1")

For row = 1 To lastRow
    str = rng.Offset(0, 1).Value
    index = InStr(rng.Value, str)
    If index > 0 Then rng.Characters(index).Font.Color = vbGreen
    Set rng = rng.Offset(1, 0)
Next row

Set rng = Nothing

答案 1 :(得分:0)

使用字典方法并突出显示字典中的密钥是否为Highlighted Result

Option Explicit

Sub HiglightColumn()

Dim MyWorkbook As Workbook
Dim MyWorksheet As Worksheet
Set MyWorkbook = Workbooks(ActiveWorkbook.Name)
Set MyWorksheet = MyWorkbook.Sheets("WorksheetName")

Dim LastRow As Long
Dim CurrentRow As Long
Dim myList As Object
Set myList = CreateObject("Scripting.Dictionary")

For CurrentRow = 2 To MyWorksheet.Cells(MyWorksheet.Rows.Count, "B").End(xlUp).row
myList.Item(Right(MyWorksheet.Range("B" & CurrentRow), 6)) = "new"
Next

For CurrentRow = 2 To MyWorksheet.Cells(MyWorksheet.Rows.Count, "A").End(xlUp).row
    If myList.Exists(Right(MyWorksheet.Range("A" & CurrentRow), 6)) Then
        With MyWorksheet.Range("A" & CurrentRow).Interior
            .Pattern = xlSolid
            .PatternColorIndex = xlAutomatic
            .Color = 5287936
            .TintAndShade = 0
            .PatternTintAndShade = 0
        End With
        Else
            With MyWorksheet.Range("A" & CurrentRow).Interior
                .Pattern = xlNone
                .TintAndShade = 0
                .PatternTintAndShade = 0
            End With
     End If
Next CurrentRow

End Sub

答案 2 :(得分:0)

此过程突出显示列protected"粗体" (更好的字?)找到的字符串中的单元格(请参阅代码中的评论)

A