vba excel两个sheet里的两列数据进行对比,提取不同的数据写到另一个sheet
我想实现上面讲到的功能,但下面这段代码在for的地方报“typemismatch”,麻烦帮我排一下错嘛,谢谢,还有一个问题就是,如果我要拿一个sheet里的两列数据现另一...
我想实现上面讲到的功能,但下面这段代码在for的地方报“type mismatch”,麻烦帮我排一下错嘛,谢谢,
还有一个问题就是,如果我要拿一个sheet里的两列数据现另一sheet里的两列数据进行对比,是不是也可以像下面这样子写呢?烦请指教!谢谢!
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" & [a65536].End(xlUp).Row)
brr = Sheet3.Range("a1:a" & [b65536].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 展开
还有一个问题就是,如果我要拿一个sheet里的两列数据现另一sheet里的两列数据进行对比,是不是也可以像下面这样子写呢?烦请指教!谢谢!
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" & [a65536].End(xlUp).Row)
brr = Sheet3.Range("a1:a" & [b65536].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个回答
展开全部
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
都要指定工作表,brr也是a列吧?
更多追问追答
追问
对,都是在A列,我想把存在差异的那一行再加上表名一起都复制出来,应该怎么写呢,
追答
两个表头是一样的,所以表头是不会复制过来的,要手工或单独的代码。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |