我正在尝试创建第三张纸,它从第一张纸和第二张纸取列,然后根据前两张纸的列值创建一个母纸。
我试图编写一个宏,但是它没有给我预期的结果。下面是我的宏代码
Sub OneCell()
Sheets("Sheet1").Columns(1).Copy Destination:=Sheets("Sheet3").Columns(1)
Sheets("Sheet1").Columns(2).Copy Destination:=Sheets("Sheet3").Columns(2)
Sheets("Sheet2").Columns(3).Copy Destination:=Sheets("Sheet3").Columns(3)
Sheets("Sheet1").Columns(3).Copy Destination:=Sheets("Sheet3").Columns(4)
Sheets("Sheet2").Columns(2).Copy Destination:=Sheets("Sheet3").Columns(5)
End Sub
工作表1中的示例数据
First Name Last Name Age Postal Code
1. Alex Greenewood 23 B3M3N4
2. Almira Hassan 24 T5R4Y6
3. Anthony Conwood 25 L4L4L4
4. Charlie Spectar 23 H4H4H4
5. Capilar Ross 24 U2U3U3
6. Meera Yu 25 S7S7S7
7. Nancy Ohak 23 E6E6E6
8. Ahmed Mu 24 Q4Q4Q4
9. Derek Tiz 25 P0P0P0
工作表2中的数据示例:
First Name Status Company Town
1. Alex Single XYZ Halifax
2. Almira Married UTY Calgary
3. Anthony Single XYZ Vancouver
4. Charlie Single YTR Delta
5. Alvy Married YYZ Kitchener
6. Ero Married YYC Waterloo
7. Capilar Married UOI Kitchener
8. Meera Single RTD Bedford
9. Nari Single HHH Waterloo
10. Nancy Single OTY Bedford
11. Vicky Married ERT Halifax
12. Ahmed Single INY Kitchener
13. Derek Single AYQ Kitchener
预期结果: 如果工作表1和工作表2具有通用的名字列,则应首先打印与该行相关的数据。如果工作表1具有不在工作表2中的额外的名字,则与之相关的行应在工作表3的末尾打印,如果工作表2具有工作表1中没有的额外的名字,则应打印与之相关的行捕获通用名后,在工作表3末尾使用该名称。
First Name Last Name Company Age Status
1. Alex Greenewood XYZ 23 Single
2. Almira Hassan UTY 24 Married
4. Anthony Conwood XYZ 25 Single
5. Charlie Spectar YTR 23 Single
6. Capilar Ross UOI 24 Married
7. Meera Yu RTD 25 Single
8. Nancy Ohak OTY 23 Single
9. Ahmed Mu INY 24 Single
10. Derek Tiz AYQ 25 Single
11. Alvy YYZ Married
12. Ero YYC Married
13. Nari HHH Single
14. Vicky ERT Married
但是基于当前的宏,输出不会达到预期的效果,并且在工作表2中出现第一个不常用的名称之后,这给了我行中不匹配的数据