用VBA对比两个excel表中的内容,并将不同打印出来
将sheet1和sheet2的不同在sheet3中显示出来,sheet3中可以写两个按钮,一个按钮单击完成比较,并将不同处用反色显示出来,一个按钮单击完成显示...
将sheet1和sheet2的不同在sheet3中显示出来,sheet3中可以写两个按钮,一个按钮单击完成比较,并将不同处用反色显示出来,一个按钮单击完成显示
展开
3个回答
展开全部
用VBA对比两个excel表中的内容,并将不同打印出来的方法:
【1】Sub aa() '只用一个按钮
Dim r, c
For r = 1 To 10
For c = 1 To 5 '区域范围为十行五列
Worksheets("Sheet3").Cells(r, c) = Worksheets("Sheet1").Cells(r, c) '复制sheet1的内容
If Worksheets("Sheet1").Cells(r, c) <> Worksheets("Sheet2").Cells(r, c) Then
Worksheets("Sheet3").Cells(r, c).Interior.ColorIndex = 3
End If
Next
Next
End Sub
【2】
Private Sub CommandButton1_Click()
Dim arr, brr, crr(1 To 1000), b As Boolean
b = False
Dim x%: x = 1
arr = Sheet2.Range("a1:a" & Sheet2.[a65536].End(xlUp).Row)
brr = Sheet3.Range("a1:a" & Sheet3.[a65536].End(xlUp).Row)
For i = 1 To UBound(arr, 1)
For j = 1 To UBound(brr, 1)
If arr(i, 1) = brr(j, 1) Then b = True: Exit For
Next
If b = False Then crr(x) = arr(i, 1): x = x + 1
b = False
Next
[a1].Resize(x - 1, 1) = Application.Transpose(crr)
End Sub
【1】Sub aa() '只用一个按钮
Dim r, c
For r = 1 To 10
For c = 1 To 5 '区域范围为十行五列
Worksheets("Sheet3").Cells(r, c) = Worksheets("Sheet1").Cells(r, c) '复制sheet1的内容
If Worksheets("Sheet1").Cells(r, c) <> Worksheets("Sheet2").Cells(r, c) Then
Worksheets("Sheet3").Cells(r, c).Interior.ColorIndex = 3
End If
Next
Next
End Sub
【2】
Private Sub CommandButton1_Click()
Dim arr, brr, crr(1 To 1000), b As Boolean
b = False
Dim x%: x = 1
arr = Sheet2.Range("a1:a" & Sheet2.[a65536].End(xlUp).Row)
brr = Sheet3.Range("a1:a" & Sheet3.[a65536].End(xlUp).Row)
For i = 1 To UBound(arr, 1)
For j = 1 To UBound(brr, 1)
If arr(i, 1) = brr(j, 1) Then b = True: Exit For
Next
If b = False Then crr(x) = arr(i, 1): x = x + 1
b = False
Next
[a1].Resize(x - 1, 1) = Application.Transpose(crr)
End Sub
展开全部
Sub aa() '只用一个按钮
Dim r, c
For r = 1 To 10
For c = 1 To 5 '区域范围为十行五列
Worksheets("Sheet3").Cells(r, c) = Worksheets("Sheet1").Cells(r, c) '复制sheet1的内容
If Worksheets("Sheet1").Cells(r, c) <> Worksheets("Sheet2").Cells(r, c) Then
Worksheets("Sheet3").Cells(r, c).Interior.ColorIndex = 3
End If
Next
Next
End Sub
Dim r, c
For r = 1 To 10
For c = 1 To 5 '区域范围为十行五列
Worksheets("Sheet3").Cells(r, c) = Worksheets("Sheet1").Cells(r, c) '复制sheet1的内容
If Worksheets("Sheet1").Cells(r, c) <> Worksheets("Sheet2").Cells(r, c) Then
Worksheets("Sheet3").Cells(r, c).Interior.ColorIndex = 3
End If
Next
Next
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这个不用VBA吧,你用个条件格式比较一下也能显示出来啊。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询