I am a relative novice at VBA. I am attempting to flag keyworded cells (ColumnA) in excel using a list of keywords (ColumnC), which will output a flag into ColumnE.
Here is a visual example of the dataset:
Link to the image
When I attempt to run this code, I am presented with the error:
"Run-tume error '13': Type mismatch" popup.
On selecting debug, the field selected is line 17: s = Cells(i, "A").Value
I am using this code from another StackOverflow query: https://superuser.com/questions/1228098/find-keywords-in-paragraphs-of-text-in-excel
Within the "Watches" portion of the debugger it shows the following information: "expression s = Cells(i, "A").Value", "Value ", "Type Variant/Integer".
Can anyone help me find what is preventing this code from executing?
Sub KeyWord_II_TheSequel()
Dim Na As Long, Nc As Long, ary, s As String
Dim r As Range, a, i As Long, outpt As String
Na = Cells(Rows.Count, "A").End(xlUp).Row
Nc = Cells(Rows.Count, "C").End(xlUp).Row
ReDim ary(1 To Nc)
i = 1
For Each r In Range("C1:C" & Nc)
ary(i) = r.Text
ary(i) = " " & ary(i) & " "
i = i + 1
Next r
For i = 1 To Na
s = Cells(i, "A").Value
s = " " & s & " "
outpt = ""
For Each a In ary
If InStr(1, s, a) > 0 Then
outpt = outpt & "," & a
End If
Next a
If outpt = "" Then
Else
Cells(i, "E").Value = Mid(outpt, 2)
End If
Next i
End Sub
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…