[英]How to Highlight Cells in Excel?
Suppose I have a cell value "Mobile achievement" so when I select this cell, all cells having both "mobile" & "achievement" values should get highlighted. 假设我有一个单元格值“移动成就”,所以当我选择此单元格时,所有同时具有“移动”和“成就”值的单元格都应突出显示。
All these cells should get highlighted: "mobile achievement" or "achievement mobile" or "abc mobile achievement" or "mobile abc achievement" or "mobile abc xyz achievement" & so on. 所有这些单元格都应突出显示:“移动成就”或“成就移动”或“ abc移动成就”或“移动abc成就”或“移动abc xyz成就”等等。
My Question is: How to Highlight Cells in Excel directly with a function ? 我的问题是:如何在函数中直接突出显示Excel中的单元格?
you may use the below function to get your results. 您可以使用以下功能获取结果。 it will return the match count with the highlight.
它将返回带有高亮显示的匹配计数。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.