EXCEL 跨表比较数据
2016-04-13 10:54
183 查看
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
相关文章推荐
- spark streaming job生成与运行
- dwr
- linux下ntp服务端配置问题
- JAVASE
- HDPJ 1087 Super Jumping! Jumping! Jumping! (DP)
- 创建虚拟机并搭建GitLab代码管理环境
- list 操作add时候 java.lang.UnsupportedOperationException 错误
- 如何在sublime text中实现函数跟踪跳转(ctags)
- 测试管理_出色测试管理者的思考[持续更新ing]
- 从Membership 到 .NET4.5 之 ASP.NET Identity
- Ubuntu Linux 12.04 LTS amd64系统本地root提权
- .NET平台下,关于数据持久层框架
- DataTables warning : Requested unknown parameter '5' from the data source for row 0
- linux监控之cacti
- mysql Federated 引擎
- Android NDK开发Crash错误定位
- ios7之后屏幕右滑返回
- 使用excel 2010时打开多个文件多个窗口-亲试
- C/C++中堆栈相关
- 轻松把玩HttpClient之配置ssl,采用设置信任自签名证书实现https