有人可以幫我弄清楚如何修改它,以便搜索和突出顯示關鍵字來自不同表格中的範圍,例如Sheets(「DATASHEET」)。Range(「B3:B41」 )?用於突出顯示基於數組的excel單元格的代碼
Sub Highlight_Keywords()
Dim vntWords As Variant
Dim lngIndex As Long
Dim rngFind As Range
Dim strFirstAddress As String
Dim lngPos As Long
vntWords = Array("sales", "fms", "siebel", "knowledgeview", "bcs", "sap", "icm", "deal hub", "its", "stg", "ssm", "gbs", "presentation central", "tsm", "methodweb", "isc", "iot", "wwgpe", "crm", "salesone", "knac", "igs", "marketing", "edvisor", "partnerworld", _
"golden circle", "gs method", "knowledge view", "stsm", "smb", "spc", "passport advantage", "references", "global business services", "sales one", "igf", "market intelligence", "ibv", "itsm", "presentation", _
"bcs marketplace", "isv", "method web", "knowledgegate", "system sales", "field management system", "crm siebel", "global technology services", "issc", "techline", "gsar", "finance", "global services", "ontarget", "ssi", "bcrs", "sales productivity center", _
"fastpass", "gs risk", "ica", "referral", "delivery excellence", "isca", "powerpoint template", "sage", "icm assetweb", "ibm global services", "customer references", "presentation template", "sales portal", "business intelligence", "7 keys", "method", "systems sales", _
"what makes you special", "stg stsm 2006", "reference", "salary letter", "sales plan", "gbsc", "global services method", "gsmethod", "sales compass", "attach connector", "seven keys", "value creation", "fss", "gsm", "know your industry", "public sector")
With ActiveSheet.UsedRange
For lngIndex = LBound(vntWords) To UBound(vntWords)
Set rngFind = .Find(vntWords(lngIndex), LookIn:=xlValues, LookAt:=xlPart)
If Not rngFind Is Nothing Then
strFirstAddress = rngFind.Address
Do
lngPos = 0
Do
lngPos = InStr(lngPos + 1, rngFind.Value, vntWords(lngIndex), vbTextCompare)
If lngPos > 0 Then
With rngFind.Characters(lngPos, Len(vntWords(lngIndex)))
.Font.Bold = True
.Font.Size = .Font.Size + 2
.Font.ColorIndex = 3
End With
End If
Loop While lngPos > 0
Set rngFind = .FindNext(rngFind)
Loop While rngFind.Address <> strFirstAddress
End If
Next
End With
End Sub
謝謝!
提示:'ActiveSheet.UsedRange'這是它正在搜索的位置:)你認爲我們應該用什麼替換它? :) – 2012-04-23 16:53:11
對不起,我可能需要更具體。我的意思是改變陣列vntWords = Array(「不同的表單元素」) – enflam3 2012-04-23 17:04:15