mike760534211
New Member
- Joined
- Sep 25, 2014
- Messages
- 13
I have a code that highlights the cell if the cell value matches the array and it is working perfectly.
I was wanting it to also add a comment to the cell it locates from the array and after much searching for this I am unable to get it to add the comment correctly to the cell it found from the array.
Any assistance would be greatly appreciated.
I was wanting it to also add a comment to the cell it locates from the array and after much searching for this I am unable to get it to add the comment correctly to the cell it found from the array.
Any assistance would be greatly appreciated.
Code:
Sub Highlight_Cell_frm_Array()
Dim vntWords As Variant
Dim lngIndex As Long
Dim rngFind As Range
Dim strFirstAddress As String
Dim lngPos As Long
vntWords = Array("array criteria here")
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