如:
sheet1中A列和C列:
A列 C列
1500 1500
1500A 1500A
1500 1500B
1500AX 1500BX
1500CX 1500CX
1500DB 1500EE
1500ED 1500ED
将A列与C列单元格内容不同的行复制到sheet2中
sheet2中A列和C列:
1500 1500B
1500AX 1500BX
1500DB 1500EE
Sub aa()
Dim sht1, sht2 As Worksheet
Set sht1 = Worksheets("Sheet1")
Set sht2 = Worksheets("Sheet2")
i = 2
j = 2
Do
If sht1.Cells(i, 1) = sht1.Cells(i, 2) Then
Else: sht2.Cells(j, 1) = sht1.Cells(i, 1)
sht2.Cells(j, 2) = sht1.Cells(i, 2)
j = j + 1
End If
i = i + 1
Loop Until sht1.Cells(i, 1) = ""
End Sub
j 和 i 是1还是2 ,你自己设定吧。
实践过了,望尽快采纳!
Dim sht1, sht2 As Worksheet
Set sht1 = Worksheets("Sheet1")
Set sht2 = Worksheets("Sheet2")
i = 2
j = 2
Do
If sht1.Cells(i, 1) = sht1.Cells(i, 2) Then
Else: sht2.Cells(j, 1) = sht1.Cells(i, 1)
sht2.Cells(j, 2) = sht1.Cells(i, 2)
j = j + 1
End If
i = i + 1
Loop Until sht1.Cells(i, 1) = ""
End Sub
j 和 i 是1还是2 ,你自己设定吧。
实践过了,望尽快采纳!
温馨提示:答案为网友推荐,仅供参考
第1个回答 2013-03-04
在模块中插入如下VBA程序:
Sub try()
Dim i As Long, k As Long
k = 1
Sheet1.Select
For i = 1 To Range("A65536").End(xlUp).Row
If Range("A" & i).Value <> Range("C" & i).Value Then
Sheet2.Range("A" & k).Value = Range("A" & i).Value
Sheet2.Range("C" & k).Value = Range("C" & i).Value
k = k + 1
End If
Next i
End Sub
Sub try()
Dim i As Long, k As Long
k = 1
Sheet1.Select
For i = 1 To Range("A65536").End(xlUp).Row
If Range("A" & i).Value <> Range("C" & i).Value Then
Sheet2.Range("A" & k).Value = Range("A" & i).Value
Sheet2.Range("C" & k).Value = Range("C" & i).Value
k = k + 1
End If
Next i
End Sub