做一个Excel 数据比较的宏,高手请进。

2024-11-06 13:43:04
推荐回答(3个)
回答1:

假若你hseet2与sheet3中数据是完全对应的就比较简单一点.
也就是说k4与k4,K5与K5比较,不能出现K4与K6比较的情况.
sub mac()
for i=4 to nn 'nn为你表中最大行的数值
If Sheets("sheet2").Cells(i, 1) < Sheets("sheet3").Cells(i, 1) Then
ss = i & ":" & i
Worksheets("Sheet2").Select
Rows(ss).Select
With Selection.Interior
.Color = 255
End With
Else
If Sheets("sheet2").Cells(i, 1).Interior.Color = 255 Then
s1 = i & ":" & i
Worksheets("Sheet2").Select

Rows(s1).Select

With Selection.Interior

.Pattern = xlNone
.TintAndShade = 0

End With
End If
End If
Next
End Sub

回答2:

假若你hseet2与sheet3中数据是完全对应的就比较简单一点.
也就是说k4与k4,k5与k5比较,不能出现k4与k6比较的情况.
sub
mac()
for
i=4
to
nn
'nn为你表中最大行的数值
if
sheets("sheet2").cells(i,
1)
<
sheets("sheet3").cells(i,
1)
then
ss
=
i
&
":"
&
i
worksheets("sheet2").select
rows(ss).select
with
selection.interior
.color
=
255
end
with
else
if
sheets("sheet2").cells(i,
1).interior.color
=
255
then
s1
=
i
&
":"
&
i
worksheets("sheet2").select
rows(s1).select
with
selection.interior
.pattern
=
xlnone
.tintandshade
=
0
end
with
end
if
end
if
next
end
sub

回答3:

好像不需要VBA,条件格式也能实现吧?