yipeng-yu
Public Sub Compare(fullname As String, sheet As String)

    Dim conn, sql, rows, i, cellContents ,rowIndex, colIndex

  rowIndex 2

  colIndex = getColumnIndex("Name")

    \'获取目标表数据
    Set conn = CreateObject("adodb.connection")
    conn.Open "provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=\'Excel 12.0\';data source=" & fullname
    sql = "select * from [" & sheet & "$]"
    rows = conn.Execute(sql).getrows
    conn.Close
  
    Do
        \'选择原表单元格
        ActiveSheet.Cells(rowIndex, colIndex).Select
    \'去除填充色 With Selection.Interior .Pattern = xlNone .TintAndShade = 0 .PatternTintAndShade = 0 End With cellContents = ActiveCell.Value
If cellContents
<> "" Then For i = 0 To UBound(rows, 2) If cellContents = rows(2, i) Then If rows(0, i) <> "apple" Then \'填充黄色 With Selection.Interior .Pattern = xlSolid .PatternColorIndex = xlAutomatic .Color = 65535 .TintAndShade = 0 .PatternTintAndShade = 0 End With End If Exit For End If Next End If rowIndex = rowIndex + 1 Loop Until cellContents = "" End Sub

 

分类:

技术点:

相关文章: