0

我试图得到这个结果:

预期结果

目前我的 vbc 脚本给了我这个:

当前 vba 代码生成的结果

这是 vlookup 的第一张表

用于 vlookup 的 Sheet1

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
4

1 回答 1

0

您正在使用具有相同值和相同标准的相同 vlookup,但期望得到不同的结果。

我相信您的具体问题与“$A2”有关。这应该是动态的。下一行应该是 $A3,然后是 $A4,以此类推。

您可以通过将 vlookup 视为字符串来实现此目的。在 $A 之后打破它以使用您的变量,然后重新加入字符串。

例如:"...RROR(VLookup($A" & j & ", Table..."

于 2018-08-09T03:19:23.060 回答