VBA Excel:通过搜索其他工作表进行排序

VBA Excel:通过搜索其他工作表进行排序,vba,excel,Vba,Excel,我试图找出如何使用两张表上的唯一标识符,通过另一张表中的信息对Excel文档中一张表中的信息进行排序 我在Excel中有两个单独的工作表,sheet1包含用户信息,包括姓名、性别和一个看起来或多或少像这样的唯一ID: A | B | C John Doe | M | 112 Jane Doe | F | 147 Kerry West | F | 293 Robert Smith | M | 861 A | B 112 | 15 147 | 1

我试图找出如何使用两张表上的唯一标识符,通过另一张表中的信息对Excel文档中一张表中的信息进行排序

我在Excel中有两个单独的工作表,
sheet1
包含用户信息,包括姓名、性别和一个看起来或多或少像这样的唯一ID:

      A      | B |  C
John Doe     | M | 112 
Jane Doe     | F | 147 
Kerry West   | F | 293
Robert Smith | M | 861
 A  | B
112 | 15
147 | 12
293 | 18
861 | 11
 A  | B  |  C  | D
112 | 15 | 147 | 12
861 | 11 | 293 | 18
第2页
包含一个唯一标识符和如下分数:

      A      | B |  C
John Doe     | M | 112 
Jane Doe     | F | 147 
Kerry West   | F | 293
Robert Smith | M | 861
 A  | B
112 | 15
147 | 12
293 | 18
861 | 11
 A  | B  |  C  | D
112 | 15 | 147 | 12
861 | 11 | 293 | 18
我想做的是在第二张表格中根据性别将两组分开。所以基本上我会在第二张纸上找到唯一的ID,在第1张纸上找到它,然后检查与唯一ID相关的性别,这样第二张纸就会变成这样:

      A      | B |  C
John Doe     | M | 112 
Jane Doe     | F | 147 
Kerry West   | F | 293
Robert Smith | M | 861
 A  | B
112 | 15
147 | 12
293 | 18
861 | 11
 A  | B  |  C  | D
112 | 15 | 147 | 12
861 | 11 | 293 | 18

因此,标识为男性的行被保留在列中,而标识为女性的行被移动到列C和D。我只是不明白我该如何做,这让我发疯。任何帮助或建议都将不胜感激。

尝试以下方式:

      A      | B |  C
John Doe     | M | 112 
Jane Doe     | F | 147 
Kerry West   | F | 293
Robert Smith | M | 861
 A  | B
112 | 15
147 | 12
293 | 18
861 | 11
 A  | B  |  C  | D
112 | 15 | 147 | 12
861 | 11 | 293 | 18
创建一个名为“Sheet3”的工作表,该工作表将填充摘要。这应该让你开始

Sub nameList()

Dim sh1 As Worksheet
Dim sh2 As Worksheet
Dim sh3 As Worksheet
Dim lc1, lc2, x, y, i, vLook

Set sh1 = Sheets("Sheet1")
Set sh2 = Sheets("Sheet2")
Set sh3 = Sheets("Sheet3")

lc1 = sh1.Cells(Rows.Count, "A").End(xlUp).Row
lc2 = sh2.Cells(Rows.Count, "A").End(xlUp).Row

x = 2
y = 2
For i = 2 To lc1
    vLook = Application.WorksheetFunction.VLookup(sh1.Cells(i, 3), Range(sh2.Cells(1, 1), sh2.Cells(lc2, 2)), 2, "false")
    If sh1.Cells(i, 2) = "M" Then
        sh3.Cells(x, 1) = sh1.Cells(i, 3)
        sh3.Cells(x, 2) = vLook
        x = x + 1
    Else
        sh3.Cells(y, 3) = sh1.Cells(i, 3)
        sh3.Cells(y, 4) = vLook
        y = y + 1
    End If
Next i

End Sub