根据另一个表中的值将数据从一个选项卡复制到另一个选项卡

时间:2022-02-18 20:10:46

I have a table "RawData" in excel I would like to filter. Column A has a name, and Column B has a number. I would like to copy the data to a different table, "LoadingData", if the name matches up with a specific number. I have the corresponding names/numbers in a different tab "ShiftData" within the worksheet.

我在Excel中有一个表“RawData”我想过滤。列A具有名称,列B具有数字。如果名称与特定数字匹配,我想将数据复制到另一个表“LoadingData”。我在工作表中的不同选项卡“ShiftData”中有相应的名称/数字。

EX. If John Smith has a 2 in the column next to him, copy the whole row to sheet "LoadingData". If John Smith has a 4 in the column next to him, do not move his data.

EX。如果John Smith在他旁边的列中有2,则将整行复制到工作表“LoadingData”。如果John Smith在他旁边的列中有4,请不要移动他的数据。

I tried using a VLOOKUP function, but I think what I'm trying to do is more complicated than that. Any help would be appreciated!

我尝试使用VLOOKUP函数,但我认为我要做的事情比这更复杂。任何帮助,将不胜感激!

1 个解决方案

#1


0  

Sub CopyData()
Const cValuetoCheck = 2
Dim rngData As Range, rngLoad As Range

    Set rngData = Worksheets("shiftdata").Range("B1")
    Set rngLoad = Worksheets("loadingdata").Range("A1")

    While Not (IsEmpty(rngData))
        If rngData = cValuetoCheck Then
            rngData.EntireRow.Copy
            rngLoad.EntireRow.PasteSpecial
            Set rngLoad = rngLoad.Offset(1, 0)
        End If
        Set rngData = rngData.Offset(1, 0)
    Wend

End Sub

#1


0  

Sub CopyData()
Const cValuetoCheck = 2
Dim rngData As Range, rngLoad As Range

    Set rngData = Worksheets("shiftdata").Range("B1")
    Set rngLoad = Worksheets("loadingdata").Range("A1")

    While Not (IsEmpty(rngData))
        If rngData = cValuetoCheck Then
            rngData.EntireRow.Copy
            rngLoad.EntireRow.PasteSpecial
            Set rngLoad = rngLoad.Offset(1, 0)
        End If
        Set rngData = rngData.Offset(1, 0)
    Wend

End Sub