簡體   English   中英

Excel上的VBA-使用vlookup的結果作為匹配條件

[英]VBA on excel - using the result of a vlookup as criteria for a match

我正在使用vlookup從表2中的table1中查找匹配項。我現在想使用查找結果來查找該特定字符串的行號。

Private Sub CommandButton1_Click()
On Error Resume Next
Dim BPP_Row As Long
Dim BPP_Clm As Long
Dim result As String
Dim num As String
Table1 = Sheet1.Range("B6:C44")
Table2 = Sheet3.Range("B6:B147")
Table3 = Sheet1.Range("C1:C44")
BPP_Row = Sheet3.Range("D6").Row
BPP_Clm = Sheet3.Range("D6").Column
For Each cl In Table2
 result = Application.WorksheetFunction.VLookup(cl, Table1, 2, False)
 num = Application.Match(""" + result + """, Table3, 0)
 Sheet3.Cells(BPP_Row, BPP_Clm).Formula = "=""" + result + """ + """ + num + """"
 BPP_Row = BPP_Row + 1
 result = ""
 num = ""
Next cl
MsgBox "done"
End Sub

設法修復它。

Private Sub CommandButton1_Click()
On Error Resume Next
Dim BPP_Row As Long
Dim BPP_Clm As Long
Dim result As String
Dim num As String
Table1 = Sheet1.Range("B6:C44")
Table2 = Sheet3.Range("B6:B147")
Table3 = Sheet1.Range("C1:C44")
BPP_Row = Sheet3.Range("D6").Row
BPP_Clm = Sheet3.Range("D6").Column
For Each cl In Table2
 result = Application.WorksheetFunction.VLookup(cl, Table1, 2, False)
 num = Application.WorksheetFunction.Match(result, Table3, 0)
 Sheet3.Cells(BPP_Row, BPP_Clm).Formula = "=""" + result + """ + " + num + ""
 BPP_Row = BPP_Row + 1
 result = ""
 num = ""
Next cl
MsgBox "done"
End Sub

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM