|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
参与一下。。。- Sub ykcbf() '//2024.1.16
- Set d = CreateObject("Scripting.Dictionary")
- Set d1 = CreateObject("Scripting.Dictionary")
- With Sheets("比2")
- r = .Cells(Rows.Count, 1).End(3).Row
- arr = .Range("a1:f" & r)
- For i = 2 To UBound(arr)
- s = CStr(arr(i, 4))
- d(s) = arr(i, 6)
- Next
- End With
- Set reg = CreateObject("VBScript.RegExp")
- On Error Resume Next
- With Sheets("比1")
- r = .Cells(Rows.Count, 1).End(3).Row
- arr = .Range("a1:g" & r)
- For i = 2 To UBound(arr)
- st = arr(i, 4)
- With reg
- .Pattern = "(\d+)$"
- End With
- Set mh = reg.Execute(st)
- If mh.Count > 0 Then
- s = mh(0).Value
- Else
- s = ""
- End If
- If Not d1.exists(s) Then
- d1(s) = Array(arr(i, 1), arr(i, 2), arr(i, 3))
- End If
- If d.exists(s) Then
- arr(i, 7) = d(s)
- End If
- Next
- .Range("a1:g" & r) = arr
- End With
- With Sheets("比2")
- r = .Cells(Rows.Count, 1).End(3).Row
- arr = .Range("a1:j" & r)
- For i = 2 To UBound(arr)
- s = CStr(arr(i, 4))
- For j = 8 To UBound(arr, 2)
- arr(i, j) = d1(s)(j - 8)
- Next
- Next
- .Range("a1:j" & r) = arr
- End With
- Set d = Nothing
- Set d1 = Nothing
- MsgBox "二表数据提取完成!"
- End Sub
复制代码
|
|