|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 cmo9020 于 2024-5-12 17:53 编辑
请教各位导师根据字符串名称进行模糊匹配,求助
TEST主控文档
执行后
1.C列与 目标A.xlsx B列 行对应
2.H列与目标D列是要进行字符串模糊比对 只要字符串内容有部份相同即可
3.上面2項都匹配才會将目标C列内容填入到当前D列(反橘色部份)
举例:
H列"port:擦边" 和目标D列 "AK-port-优-JR-侧边"字符串内容都有"port"这样就可以
现在代码只有做到C列与目标B列做比对...
模糊比对部份不会,请导师们出手帮助一下~谢谢
Test.7z
(24.93 KB, 下载次数: 3)
Sub Update333()
Dim wb As Workbook, dic As Object
Dim i As Integer, j As Long
Dim arr, s
Dim Target As Range
Dim cell As Range
Set Target = Range("C1:C" & Cells(Rows.Count, 1).End(xlUp).Row)
Dim filePath As String
filePath = ThisWorkbook.Path & "\A.xlsx"
Set wb = Workbooks.Open(filePath)
Set dic = CreateObject("Scripting.Dictionary")
j = wb.Worksheets("Sheet1").Range("B65536").End(xlUp).Row
With wb.Worksheets("Sheet1")
arr = .Range("A1:G" & j)
For i = 2 To j
dic(.Cells(i, 2).Value) = .Cells(i, 2).Value & "|" & .Cells(i, 3).Value
Next
End With
For Each cell In Target
If cell.Value <> "" Then
If dic.Exists(cell.Value) Then
s = Split(dic(cell.Value), "|")
If cell.Offset(0, 2) = "" Then
cell.Offset(0, 1) = s(1)
End If
End If
End If
Next cell
wb.Close SaveChanges:=False
Set wb = Nothing
Set dic = Nothing
End Sub
|
|