|
ashengz86 发表于 2012-12-13 17:36
Q4_10_other Q4_10_other-code1 对SQ4
Q10_06_other Q10_06_other-code1 对Q10_ ... - Sub Macro1()
- Dim cnn, rs, SQL$, arr, i&, j&
- Set cnn = CreateObject("adodb.connection")
- Set rs = CreateObject("adodb.Recordset")
- cnn.Open "provider=Microsoft.ACE.OLEDB.12.0;extended properties=excel 12.0;data source=" & ThisWorkbook.Path & "\B.xlsx"
- SQL = "select b.SQ4,b.SQ4,b.Q10_6,b.Q10_95,b.Q10_96,b.Q10_97 from [Excel 12.0;Database=" & ThisWorkbook.FullName & "].[Sheet1$] a left join [Sheet1$] b on a.ID=b.SERIAL"
- rs.Open SQL, cnn, 1, 3
- Cells.Interior.Pattern = xlNone
- arr = [a1].CurrentRegion
- For i = 2 To UBound(arr)
- For j = 3 To 8
- If (Len(arr(i, j)) > 0 And rs.Fields(j - 3).Value = 0) Or (Len(arr(i, j)) = 0 And rs.Fields(j - 3).Value = 1) Then
- Cells(i, j).Interior.Color = 65535
- Cells(i, 1).Interior.Color = 192
- End If
- Next
- rs.MoveNext
- Next
- rs.Close
- cnn.Close
- Set rs = Nothing
- Set cnn = Nothing
- End Sub
复制代码 |
|