我的代码未返回预期值(VBA)

时间:2019-09-11 09:50:21

标签: excel vba

我想获得一个称为卷的工作表中的卷,在此工作表中,我有2019年至2026年的许多卷,并且该行中有许多项目。

我想通过将工作表Loaded_Plan的C列中的每个单元格与工作表Volumes的C列中的每一行进行比较来获得体积。我试图为此在Loaded_Plan工作表中创建Y列,但是它不起作用。下面是代码:

Dim rngProject Set rngProject = wsVolumes.Range(wsVolumes.Cells(5, "B"), wsVolumes.Cells(wsVolumes.Rows.Count, "B").End(xlUp)) 'Dim rngVolume Set rngVolume = wsVolumes.Range(wsVolumes.Cells(5, "B"), wsVolumes.Cells(wsVolumes.Rows.Count, "V").End(xlUp))

For Each cell In rngProject

    wsLoaded_Plan.Cells(cell.Row, cell.Column + 23).Value = Application.VLookup(cell, wsLoaded_Plan.Range("C:C"), 1, False)
    ' Ne copie colle que cette ligne d'après
    wsLoaded_Plan.Cells(cell.Row, cell.Column + 8).Value = Application.VLookup(wsLoaded_Plan.Cells(cell.Row, cell.Column + 23).Value, rngVolume, 4, False)
    wsLoaded_Plan.Cells(cell.Row, cell.Column + 10).Value = Application.VLookup(wsLoaded_Plan.Cells(cell.Row, cell.Column + 23).Value, rngVolume, 5, False)
    wsLoaded_Plan.Cells(cell.Row, cell.Column + 12).Value = Application.VLookup(wsLoaded_Plan.Cells(cell.Row, cell.Column + 23).Value, rngVolume, 6, False)
    wsLoaded_Plan.Cells(cell.Row, cell.Column + 14).Value = Application.VLookup(wsLoaded_Plan.Cells(cell.Row, cell.Column + 23).Value, rngVolume, 7, False)
    wsLoaded_Plan.Cells(cell.Row, cell.Column + 16).Value = Application.VLookup(wsLoaded_Plan.Cells(cell.Row, cell.Column + 23).Value, rngVolume, 8, False)
    wsLoaded_Plan.Cells(cell.Row, cell.Column + 20).Value = Application.VLookup(wsLoaded_Plan.Cells(cell.Row, cell.Column + 23).Value, rngVolume, 9, False)
    wsLoaded_Plan.Cells(cell.Row, cell.Column + 22).Value = Application.VLookup(wsLoaded_Plan.Cells(cell.Row, cell.Column + 23).Value, rngVolume, 10, False)
 Next cell

Dim rngProject
    Set rngProject = wsVolumes.Range(wsVolumes.Cells(5, "B"), wsVolumes.Cells(wsVolumes.Rows.Count, "B").End(xlUp))
    Dim rngVolume
    Set rngVolume = wsVolumes.Range(wsVolumes.Cells(5, "B"), wsVolumes.Cells(wsVolumes.Rows.Count, "V").End(xlUp))

    For Each cell In rngProject

        wsLoaded_Plan.Cells(cell.Row, cell.Column + 23).Value = Application.VLookup(cell, wsLoaded_Plan.Range("C:C"), 1, False)
        ' Ne copie colle que cette ligne d'après
        wsLoaded_Plan.Cells(cell.Row, cell.Column + 8).Value = Application.VLookup(wsLoaded_Plan.Cells(cell.Row, cell.Column + 23).Value, rngVolume, 4, False)
        wsLoaded_Plan.Cells(cell.Row, cell.Column + 10).Value = Application.VLookup(wsLoaded_Plan.Cells(cell.Row, cell.Column + 23).Value, rngVolume, 5, False)
        wsLoaded_Plan.Cells(cell.Row, cell.Column + 12).Value = Application.VLookup(wsLoaded_Plan.Cells(cell.Row, cell.Column + 23).Value, rngVolume, 6, False)
        wsLoaded_Plan.Cells(cell.Row, cell.Column + 14).Value = Application.VLookup(wsLoaded_Plan.Cells(cell.Row, cell.Column + 23).Value, rngVolume, 7, False)
        wsLoaded_Plan.Cells(cell.Row, cell.Column + 16).Value = Application.VLookup(wsLoaded_Plan.Cells(cell.Row, cell.Column + 23).Value, rngVolume, 8, False)
        wsLoaded_Plan.Cells(cell.Row, cell.Column + 20).Value = Application.VLookup(wsLoaded_Plan.Cells(cell.Row, cell.Column + 23).Value, rngVolume, 9, False)
        wsLoaded_Plan.Cells(cell.Row, cell.Column + 22).Value = Application.VLookup(wsLoaded_Plan.Cells(cell.Row, cell.Column + 23).Value, rngVolume, 10, False)
     Next cell

 End

End Sub

我希望从表Volumes中的列从F,G,H,I,J,K,L,M到第I,K列中的表Loaded_Plan的体积,关于项目的M,O,Q,S,U,W。我想要的是两卷:一本是2019年,另一本是2020年(但未在适当的行中完成,项目之间的匹配不正确)。

0 个答案:

没有答案