关于VBA使用vlookup匹配数据
答案:2 悬赏:30 手机版
解决时间 2021-11-24 18:46
- 提问者网友:椧運幽默
- 2021-11-24 11:49
关于VBA使用vlookup匹配数据
最佳答案
- 五星知识达人网友:神鬼未生
- 2021-11-24 12:23
Sub 填写内容123()
Dim i As Integer
Dim s As String
Dim rg As Range
Dim arr As Variant
Dim sh1, sh2
Dim res As Variant
Set sh1 = Worksheets("Sheet1")
Set sh2 = Worksheets("Sheet2")
Set rg = sh1.Range("a3:b" & sh1.[b65536].End(xlUp).Row) 'sh1.
'arr = Range("g3:h" & [h65536].End(xlUp).Row)
For i = 2 To [C65536].End(xlUp).Row 'C--e
s = sh2.Cells(i, 3)
res = Application.VLookup(s, rg, 2, False)
Cells(i, 4) = IIf(IsError(res), "", res)
Next i
End Sub
Dim i As Integer
Dim s As String
Dim rg As Range
Dim arr As Variant
Dim sh1, sh2
Dim res As Variant
Set sh1 = Worksheets("Sheet1")
Set sh2 = Worksheets("Sheet2")
Set rg = sh1.Range("a3:b" & sh1.[b65536].End(xlUp).Row) 'sh1.
'arr = Range("g3:h" & [h65536].End(xlUp).Row)
For i = 2 To [C65536].End(xlUp).Row 'C--e
s = sh2.Cells(i, 3)
res = Application.VLookup(s, rg, 2, False)
Cells(i, 4) = IIf(IsError(res), "", res)
Next i
End Sub
全部回答
- 1楼网友:躲不过心动
- 2021-11-24 12:55
试下这个
Sub 填写内容123()
On Error Resume Next
Dim i As Integer
For i = 2 To [C65536].End(xlUp).Row
Cells(i, "D") = WorksheetFunction.VLookup(Cells(i, "C"), Sheets("数据透视表").Range("A:B"), 2, 0)
Next
End Sub
代码放到 单位这个表
Sub 填写内容123()
On Error Resume Next
Dim i As Integer
For i = 2 To [C65536].End(xlUp).Row
Cells(i, "D") = WorksheetFunction.VLookup(Cells(i, "C"), Sheets("数据透视表").Range("A:B"), 2, 0)
Next
End Sub
代码放到 单位这个表
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯