[英]Vlookup function returning same results for different row cells
我試圖得到這個結果:
目前我的 vbc 腳本給了我這個:
這是制作 vlookup 的第一個工作表
Sub Suivi()
With ActiveSheet
.Unprotect Password:="capreit"
Rows("2:" & Rows.Count).ClearContents
Worksheets("Suivi Déménagement").Cells.Borders.LineStyle = xlNone
Dim i As Integer
j = 2
For i = 4 To Sheets("Tableau").Range("A4").SpecialCells(xlLastCell).Row
If Sheets("Tableau").Cells(i, 2).Value = "Nouveau locataire" Or Sheets("Tableau").Cells(i, 2).Value = "Décès" Or Sheets("Tableau").Cells(i, 2).Value = "Skip" And Evaluate("OR(ISNUMBER(MATCH({""*-*""},{""" & Sheets("Tableau").Cells(i, 1).Value & """},0)))") Then
Sheets("Suivi Déménagement").Cells(j, 1) = Sheets("Tableau").Cells(i, 1)
Sheets("Suivi Déménagement").Cells(j, 2).Formula = "=IFERROR(VLookup($A2,Tableau!$A:$T,4,FALSE),"""")"
Sheets("Suivi Déménagement").Cells(j, 3).Formula = "=IFERROR(VLookup($A2,Tableau!$A:$T,3,FALSE),"""")"
Sheets("Suivi Déménagement").Cells(j, 4).Formula = "=IFERROR(VLookup($A2,Tableau!$A:$T,2,FALSE),"""")"
Sheets("Suivi Déménagement").Cells(j, 5).Formula = "=IFERROR(VLookup($A2,Tableau!$A:$T,18,FALSE),"""")"
Sheets("Suivi Déménagement").Cells(j, 6).Formula = "=IFERROR(VLookup($A2,Tableau!$A:$T,19,FALSE),"""")"
j = j + 1
End If
Next i
您正在使用具有相同值和相同條件的相同 vlookup,但期望得到不同的結果。
我相信你的具體問題是“$A2”。 這應該是動態的。 下一行應該是 $A3,然后是 $A4,依此類推。
您可以通過將 vlookup 視為字符串來實現此目的。 在 $A 之后打破它以使用您的變量,然后重新加入字符串。
例如: "...RROR(VLookup($A" & j & ", Tabl...."
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.