|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub Compare()
Dim rg1 As Range, rg2 As Range, s As String, pro As String, str As String, i As Integer
On Error GoTo err
Set rg1 = Application.InputBox("选择对比区域1", "选择老表数据区", , , , , , 8)
If rg1.Cells.Count Then
s = "已选择区域:" & rg1.Address(1, 1, xlR1C1) & Chr(10) & "选择对比区域2"
Set rg2 = Application.InputBox(s, "选择新表数据区", , , , , , 8)
If rg2.Cells.Count Then
If (rg1.Rows.Count = rg2.Rows.Count) And (rg1.Columns.Count = rg2.Columns.Count) Then
For i = 1 To (rg1.Rows.Count * rg1.Columns.Count)
If rg1.Cells(i) <> rg2.Cells(i) Then
rg1.Cells(i) = rg2.Cells(i)
End If
Next i
str = MsgBox("已复制新增数据", vbOKOnly, "处理完成")
Else
pro = "错误提示:" & Chr(10) & "已选择区域1:" & rg1.Address(1, 1, xlR1C1) & Chr(10) & "已选择区域2:" & rg2.Address(1, 1, xlR1C1)
str = MsgBox(pro, vbExclamation, "选择的两个区域大小不一致,无法处理")
End If
End If
Else
err:
str = MsgBox("未执行")
End If
End Sub |
|