ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 663|回复: 2

[求助] 核对不同数据的显示颜色

[复制链接]

TA的精华主题

TA的得分主题

发表于 2019-12-24 18:21 | 显示全部楼层 |阅读模式
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
hi, 我想要核对2个区域指定的数据,若是不同的标黄色。

如截图,这有2个区域的数据。如H列区域的AA-Auto跟N列AA-Auto核对他们点击数和花费,即I列和O列比较,J列和P列比较。
可我运行代码,不知为何J列和P列的数据一样,也会显示颜色,相同的不应该显示颜色,但是这不知哪里出了问题。多谢

Sub 核对数据()
Dim r, rp, col, g, y As Byte
Dim d, dr As Object

Cells.Interior.Color = xlNone
r = Cells(Rows.Count, "n").End(xlUp).Row
rp = Cells(Rows.Count, "h").End(xlUp).Row
Set d = CreateObject("scripting.dictionary")
Set dr = CreateObject("scripting.dictionary")
For y = 2 To r
    d(Cells(y, "n").Value) = Cells(y, "o").Value
    dr(Cells(y, "n").Value) = Cells(y, "p").Value
Next

For y = 2 To rp - 1
    If d(Cells(y, "h").Value) <> Cells(y, "i").Value Then Cells(y, "h").Interior.Color = vbYellow
    If dr(Cells(y, "h").Value) <> Cells(y, "j").Value Then Cells(y, "h").Interior.Color = vbYellow
Next
MsgBox r & Chr(10) & rp
End Sub




问题.png

问题1.rar

20.5 KB, 下载次数: 3

TA的精华主题

TA的得分主题

 楼主| 发表于 2019-12-25 11:14 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
我知道问题所在了,因为小数的问题,不知是不是数字型有的问题还是怎样。我是把有小数的列以“.”来分列,然后在用&字符连接起来,再运行我的代码就可以了。

TA的精华主题

TA的得分主题

 楼主| 发表于 2019-12-25 12:14 | 显示全部楼层
已解决

Sub 核对数据()
Dim r, rp, col, y As Byte
Dim d, dr As Object
Dim a, b, c, f, g, h As Byte

Application.FindFormat.Clear
a = Cells.Find("源数据", lookat:=xlWhole).Column
b = Cells.Find("Click", lookat:=xlWhole).Column
c = Cells.Find("Spend", lookat:=xlWhole).Column
f = Cells.Find("Campaigns", lookat:=xlWhole).Column
g = Cells.Find("Clicks", lookat:=xlWhole).Column
h = Cells.Find("Spend(USD)", lookat:=xlWhole).Column

Cells.Interior.Color = xlNone
r = Cells(Rows.Count, f).End(xlUp).Row
rp = Cells(Rows.Count, a).End(xlUp).Row
Set d = CreateObject("scripting.dictionary")
Set dr = CreateObject("scripting.dictionary")
For y = 2 To r
    If InStr(Cells(y, h), ".") Then Cells(y, h) = Split(Cells(y, h).Value, ".")(0) & "." & Split(Cells(y, h).Value, ".")(1)
    d(Cells(y, f).Value) = Cells(y, g).Value
    dr(Cells(y, f).Value) = Cells(y, h).Value
Next

For y = 2 To rp - 1
    If InStr(Cells(y, c), ".") Then Cells(y, c) = Split(Cells(y, c).Value, ".")(0) & "." & Split(Cells(y, c).Value, ".")(1)
    If d(Cells(y, a).Value) <> Cells(y, b).Value Then Cells(y, a).Interior.Color = vbYellow
    If dr(Cells(y, a).Value) <> Cells(y, c).Value Then Cells(y, a).Interior.Color = vbYellow
Next
MsgBox r & Chr(10) & rp
End Sub

问题1.rar

21.54 KB, 下载次数: 1

您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-4-27 06:19 , Processed in 0.032794 second(s), 11 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表