Excel中如何用VBA检查sheet1中A列与C列单元格内容是否一致,不一致的显示在sheet2中
如:sheet1中A列和C列:A列C列150015001500A1500A15001500B1500AX1500BX1500CX1500CX1500DB1500EE150...
如:
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 展开
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 展开
2个回答
展开全部
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 ,你自己设定吧。
实践过了,望尽快采纳!
百事牛
2024-10-28 广告
2024-10-28 广告
针对Excel表格的密码解锁问题,深圳奥凯丰科技有限公司提供专业的软件解决方案,旨在帮助用户快速、安全地恢复或移除表格中的保护密码。我们的软件采用先进的密码恢复技术,能够有效应对多种加密类型,包括工作簿打开密码、工作表保护密码等。用户只需简...
点击进入详情页
本回答由百事牛提供
展开全部
在模块中插入如下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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询