excel - 使用 VBA 替代 Vlookup。比较列中的值并将相应值从第二列复制到另一列
问题描述
我有一个任务,我不想使用vlookup
,因为它使过程非常缓慢。我正在为该任务寻找一个纯粹的 VBA 代码解决方案。
在这里,我将工作表 2 中 A 列和 D 列中的值合并。如果工作表 1 的 A 和 B 列中的值与工作表 2 中的值相同,那么我将工作表 2 中 G 列中的相应值复制到 D 列表 1。
Application.ScreenUpdating = False
Sheets("Sending List").Select
Dim Lastrow1, Lastrow2 As Long
Dim ws1, ws2 As Worksheet
Dim tempVal, tempVal2 As String
Set ws1 = Sheets("Sending List")
Set ws2 = Sheets("P13 D-Chain Status")
Lastrow1 = ws1.Range("B" & Rows.Count).End(xlUp).Row
Lastrow2 = ws2.Range("B" & Rows.Count).End(xlUp).Row
With ws2
.Range("Q2:Q" & Lastrow2).Formula = "=A2&D2"
.Range("R2:R" & Lastrow2).Formula = "=G2"
End With
With ws1
.Range("D2:D" & Lastrow1).Formula = "=VLOOKUP(A2&B2,'P13 D-Chain Status'!Q:R,2,0)"
End With
Application.ScreenUpdating = True
End Sub
解决方案
试试这个:
=INDEX('P13 D-Chain 状态'!Q:R,MATCH(A2&B2,'P13 D-Chain 状态'!Q:Q,0),2)
但我认为它不会工作得更快。
希望能帮助到你
推荐阅读
- javascript - 为什么在socket io中他们在html页面中有一组脚本行?
- sublimetext3 - 如何在 Sublime Text 3 中更改侧边栏的字体?
- onvif - 我可以得到网络摄像机的方向吗?
- sql - 如何从 ef core 中的 sql 获取 sys.databases 或 sys.tables
- flutter - 在行中重复小部件 n 次
- spring - 在 Spring 中何时使用 Qualifier 和 Primary
- reactjs - 如何为功能组件中的文本框设置状态
- python - 获取逻辑回归的错误误差曲线(代码中的错误)
- perl - Perl qx() 命令未按预期工作
- azure - 如何在 Azure 上打开 D:\a\r1\a\?