|
右边要求:- Sub 下发学籍编号()
- Dim cnn As Object, rs As Object
- Dim SQL As String, arr, brr$(), crr$(), drr(), i&, l&, j&, n&, t, s$, d As Object, ds As Object
- Set d = CreateObject("scripting.dictionary")
- Set ds = CreateObject("scripting.dictionary")
- Set cnn = CreateObject("ADODB.Connection")
- cnn.Open "Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=" & ThisWorkbook.Path & ";Exclusive=No;"
- Set rs = CreateObject("ADODB.Recordset")
- SQL = "select 学籍编号,姓名,性别,班级,联系电话 from z221801"
- rs.Open SQL, cnn, 1, 3
- With Sheets("下发学籍编号")
- ReDim brr(1 To rs.RecordCount, 4)
- For i = 1 To rs.RecordCount
- For j = 0 To 4
- brr(i, j) = rs.Fields(j).Value
- Next
- d(brr(i, 0)) = i
- rs.MoveNext
- Next
- SQL = "select 学籍编号,电话 from zj221800"
- Set rs = CreateObject("ADODB.Recordset")
- rs.Open SQL, cnn, 1, 3
- ReDim crr(1 To rs.RecordCount, 2)
- For i = 1 To rs.RecordCount Step 2
- m = m + 1
- n = 0
- crr(m, 0) = rs.Fields(0).Value
- ds(crr(m, 0)) = m
- For l = i To i + 1
- n = n + 1
- crr(m, n) = rs.Fields(1).Value
- rs.MoveNext
- Next l
- Next i
- arr = .Range("A2:F" & .Range("A65536").End(xlUp).Row)
- ReDim drr(1 To UBound(arr), 1 To 11)
- For i = 1 To UBound(arr)
- t = d("" & arr(i, 1))
- t2 = ds("" & arr(i, 1))
- If t <> "" And t2 <> "" Then
- drr(i, 1) = brr(t, 4)
- drr(i, 2) = crr(t, 1)
- drr(i, 3) = crr(t, 2)
- drr(i, 4) = brr(t, 0)
- drr(i, 5) = brr(t, 1)
- drr(i, 6) = brr(t, 3)
- drr(i, 7) = brr(t, 2)
- If arr(i, 4) <> drr(i, 5) Then drr(i, 9) = "有误"
- If arr(i, 6) <> drr(i, 6) Then drr(i, 10) = "有误"
- If arr(i, 5) <> drr(i, 7) Then drr(i, 11) = "有误"
- Else
- For j = 1 To 7
- drr(i, j) = "缺录"
- Next
- For j = 8 To 11
- drr(i, j) = "有误"
- Next
- End If
- Next
- .Range("g2").Resize(i - 1, 11) = drr
- End With
- rs.Close
- cnn.Close
- Set rs = Nothing
- Set cnn = Nothing
- End Sub
复制代码 |
|