在标题中search关键字

我使用下面的代码在一个有标题的单元格中关联一组关键字。 在运行代码即时获取“运行时错误13”types不匹配b = cell.Value行。

Application.ScreenUpdating = False Dim col As Range, cell1 As Range, a As String, b As String, i As Integer Set col = Range("KW[KW1]") Dim target, cell As Range Sheets("Data").Select Set target = Range(Range("B1"), Range("B65536").End(xlUp)) Dim term, tag As String For Each cell1 In col a = cell1.Value term = a tag = a For Each cell In target b = cell.Value ' If InStr(1, " " & cell & " ", " " & term & " ", 1) Then If Module1.ExactWordInString(b, a) Then For i = 1 To 15 If cell.Offset(0, i).Value = "" Then cell.Offset(0, i).Value = tag Exit For End If Next i End If Next cell Next cell1 Application.ScreenUpdating = True 

然而,如果我们有1000列的倾斜,它的运行是完美的,但是我想运行这个代码大范围高达50,000到200,000。 请帮帮我。

试试这个,你没有把目标声明为一个范围,可能就是这样。

顺便说一句,当你比较stringVBA是区分大小写的,所以尝试使用Lcase()如果你只想比较内容!

 Application.ScreenUpdating = False Dim target As Range, cell As Range Dim term As String, tag As String Dim col As Range, cell1 As Range, a As String, b As String, i As Integer Sheets("Data").Select Set col = Range("KW[KW1]") Set target = Range(Range("B1"), Range("B65536").End(xlUp)) For Each cell1 In col a = Cstr(cell1.Value) term = a tag = a For Each cell In target b = Cstr(cell.Value) 'If InStr(1, " " & cell & " ", " " & term & " ", 1) Then If Module1.ExactWordInString(b, a) Then For i = 1 To 15 If cell.Offset(0, i).Value = "" Then cell.Offset(0, i).Value = tag Exit For End If Next i End If Next cell Next cell1 Application.ScreenUpdating = True