如何在Excel中突出显示单元格?

假设我有一个单元值“移动成就”,所以当我select这个单元格时,所有具有“移动”和“成就”值的单元格应该被突出显示。

所有这些细胞都应该突出显示:“移动成就”或“成就移动”或“移动abc成就”或“移动abc成就”或“移动abc xyz成就”等。

我的问题是:如何使用函数直接在Excel中突出显示单元格?

你可以使用下面的函数来得到你的结果。 它将返回高亮显示的匹配数。

 Public Function highlightrange(texttocheck As String, r As Range) Dim totalmatchcount As Integer Dim matchcount As Integer r.Cells.Font.ColorIndex = 0 matchcount = 0 texttocheck = Replace(texttocheck, " ", "") str1 = Split(texttocheck, " ") str2 = UBound(str1) For i = 1 To r.Cells.Count For j = 0 To str2 If InStr(r.Cells(i), str1(j)) > 0 Then matchcount = matchcount + 1 End If Next j If matchcount = str2 + 1 Then r.Cells(i).Font.ColorIndex = 8 totalmatchcount = totalmatchcount + 1 End If matchcount = 0 Next i highlightrange = totalmatchcount End Function 

在这里输入图像说明