我有一本Excel工作簿,其中我有一张DataEntry
表和许多其他表。我要做的是基于DataEntry
表和Sheet1
之间的列(至少2)匹配,我想选择DataEntry
表的第三列的值并将其插入匹配相应列中的Sheet1
行。
我的数据如下:
DataEntry
表格
A B C
+----------+--------+---------+
| Roll No | Name | Marks |
+----------+--------+---------+
| 101 | abc | 45 |
| 102 | def | 25 |
| 103 | ghi | 65 |
| ... | ... | .. |
| 201 | ijk | 45 |
| 202 | lmn | 35 |
| 203 | opq | 65 |
| ... | ... | .. |
| 301 | rst | 15 |
| 302 | uvw | 57 |
| 303 | xyz | 48 |
| ... | ... | .. |
+----------+--------+---------+
11-Green-English
表格
A B C
+----------+--------+---------+
| Roll No | Name | Marks |
+----------+--------+---------+
| 101 | abc | -- |
| 102 | def | -- |
| 103 | ghi | -- |
| ... | ... | .. |
+----------+--------+---------+
11-Blue-English
表格
A B C
+----------+--------+---------+
| Roll No | Name | Marks |
+----------+--------+---------+
| 201 | ijk | -- |
| 202 | lmn | -- |
| 203 | opq | -- |
| ... | ... | .. |
+----------+--------+---------+
11-White-English
表格
A B C
+----------+--------+---------+
| Roll No | Name | Marks |
+----------+--------+---------+
| 301 | rst | -- |
| 302 | uvw | -- |
| 303 | xyz | -- |
| ... | ... | .. |
+----------+--------+---------+
我想将数据输入DataEntry
表并更新11-Green-English
表,11-Blue-English
表,11-White-English
表和类似的表格。
我尝试了以下功能,但它不适用于很多工作表:
Sub update()
Dim cell1, cell2, col1, col2 As Range
For Each cell1 In Worksheets("Sheet1").Range("A:A")
If IsEmpty(cell1.Value) Then Exit For
For Each cell2 In Worksheets("Sheet2").Range("A:A")
If IsEmpty(cell2.Value) Then Exit For
If cell1.Value = cell2.Value Then
Worksheets("Sheet1").Cells(cell1.Row, 2) = _
Worksheets("Sheet2").Cells(cell2.Row, 2)
End If
Next cell2
Next cell1
End Sub
但是,我尝试了以下Excel公式,但它不适用于超过1张:
=INDEX('DataEntry-Group-A'!C:C, MATCH(A4&B4, '11-Urdu-G'!A:A&'11-Urdu-G'!B:B, 0))