|
- Sub test()
- '-----------------问题1-----------------------
- Dim arrBaoMing()
- arrBaoMing = Sheets("报名").Range("A1").CurrentRegion.Value
- Dim arrXiTong()
- arrXiTong = Sheets("系统").Range("A1").CurrentRegion.Value
- Dim arrDiQu()
- arrDiQu = Sheets("地区").Range("A1").CurrentRegion.Value
-
- Dim i%, j%
- For i = 2 To UBound(arrBaoMing, 1)
- '获取系统成绩
- For j = 4 To UBound(arrXiTong, 1)
- If (arrBaoMing(i, 2) & arrBaoMing(i, 3)) = _
- (arrXiTong(j, 3) & arrXiTong(j, 6)) Then
- arrBaoMing(i, 10) = arrXiTong(j, 13)
- End If
- Next
-
- '获取地区成绩
- For j = 2 To UBound(arrDiQu, 1)
- If (arrBaoMing(i, 2) & arrBaoMing(i, 3)) = _
- (arrDiQu(j, 4) & arrDiQu(j, 5)) Then
- arrBaoMing(i, 11) = arrDiQu(j, 8)
- End If
- Next
- Next
- '-----------------问题2-----------------------
-
- '补系统表有名但报名表没名的
- Dim Exist As Boolean
- Dim arrTransTmp()
- For i = 4 To UBound(arrXiTong, 1)
- If i = 28 Then Stop
- Exist = False
- For j = 2 To UBound(arrBaoMing, 1)
- If arrXiTong(i, 3) & arrXiTong(i, 6) = _
- arrBaoMing(j, 2) & arrBaoMing(j, 3) Then
- Exist = True
- Exit For
- End If
- Next
-
- If Not Exist Then
- arrTransTmp = Application.Transpose(arrBaoMing) '由于二维数组只能给最后维扩容,故进入数组转置
- ReDim Preserve arrTransTmp(1 To 11, 1 To UBound(arrTransTmp, 2) + 1) '扩充数组
- arrBaoMing = Application.Transpose(arrTransTmp) '再转置回来
- arrBaoMing(UBound(arrBaoMing, 1), 2) = arrXiTong(i, 3) '补名字
- arrBaoMing(UBound(arrBaoMing, 1), 3) = arrXiTong(i, 6) '补身份证
- arrBaoMing(UBound(arrBaoMing, 1), 10) = arrXiTong(i, 13) '补系统成绩
- arrBaoMing(UBound(arrBaoMing, 1), 9) = "没有名字"
- End If
-
- Next
-
- '补地区表有名但报名表没名的
- For i = 2 To UBound(arrDiQu, 1)
- Exist = False
- For j = 2 To UBound(arrBaoMing, 1)
- If arrDiQu(i, 4) & arrDiQu(i, 5) = _
- arrBaoMing(j, 2) & arrBaoMing(j, 3) Then
- Exist = True
- Exit For
- End If
- Next
-
- If Not Exist Then
- arrTransTmp = Application.Transpose(arrBaoMing) '由于二维数组只能给最后维扩容,故进入数组转置
- ReDim Preserve arrTransTmp(1 To 11, 1 To UBound(arrTransTmp, 2) + 1) '扩充数组
- arrBaoMing = Application.Transpose(arrTransTmp) '再转置回来
- arrBaoMing(UBound(arrBaoMing, 1), 2) = arrDiQu(i, 4) '补名字
- arrBaoMing(UBound(arrBaoMing, 1), 3) = arrDiQu(i, 5) '补身份证
- arrBaoMing(UBound(arrBaoMing, 1), 10) = arrDiQu(i, 8) '补地区成绩
- arrBaoMing(UBound(arrBaoMing, 1), 9) = "没有名字"
- End If
- Next
- '输出新报名表,把[t1]换成[a1]就是放回原位。
- Sheets("报名").[t1].Resize(UBound(arrBaoMing, 1), 11).Value = arrBaoMing
-
- MsgBox "OK"
- End Sub
复制代码 |
|