EXCEL中怎样用VBA提取两列数据相同的数放在指定单元格中?

加200分

Sub s()
    For i = 607 To 2 Step -1
        If Cells(i, 1) = Cells(i, 9) Then
            Cells(i, 1).Copy [h607]
            Exit For
        End If
    Next
    Dim arr(1 To 3)
    t = [a607].Text
    For i = 1 To 3
        arr(i) = Mid(t, i, 1)
    Next
    For i = 607 To 2 Step -1
        If Cells(i, 13) = Cells(i, 9) Then
            For j = 1 To 3
                If InStr(Cells(i, 13).Text, arr(j)) > 0 Then GoTo 1
            Next
            Cells(i, 9).Copy [h606]
            Exit For
        End If
1:
    Next
End Sub
温馨提示:内容为网友见解,仅供参考
第1个回答  2015-07-21
不是不能做,是你说的听不懂,相同的意思是什么行号和内容都相同还是只要内容相同就行追问

是指两列中相同的数,如:A列与I列从下往上看第一个相同的数就是432。I列与M列从下往上看第一个相同的数是874,两列中相同的数不止一个,只要从下往上看的第一个就行了,行号不必相同。

追答

Sub x()
Dim a%, i%, m%
For a = 607 To 2 Step -1
For i = 607 To 2 Step -1
If Cells(a, 1) = Cells(i, 9) Then
[h607] = Cells(a, 1)
GoTo 0
Next
Next
0:
For i = 607 To 2 Step -1
For m = 607 To 2 Step -1
If Cells(i, 9) = Cells(m, 13) And Cells(i, 9) [a607] Then
[h606] = Cells(i, 9)
End Sub
Next
Next
End Sub

追问

运行代码时,错误:NexT没有FOR。

追答

Sub x()
Dim a%, i%, m%
For a = 607 To 2 Step -1
For i = 607 To 2 Step -1
If Cells(a, 1) = Cells(i, 9) Then
[h607] = Cells(a, 1)
GoTo 0
endif
Next
Next
0:
For i = 607 To 2 Step -1
For m = 607 To 2 Step -1
If Cells(i, 9) = Cells(m, 13) And Cells(i, 9) [a607] Then
[h606] = Cells(i, 9)
exit Sub
endif
Next
Next
End Sub

追问

不行,不能按要求找到数。

追答

我已经测试过的,如果还不行那肯定是你描述问题

追问

我试了,条件2中的要不含有A607中任何一个数字没有满足。你在A607中改为156,I列和M列都改一个219。结果219提出来了,而219含有1,5,6中的一个数字1,是不合要求的。

追答

晕,你的a607都拆成一个一个的数字来看?
那太麻烦了,懒得给你写了,自己改改吧

本回答被提问者采纳
第2个回答  2015-07-22
太麻烦,你想干什么,说出来可能有别的办法实现
第3个回答  2017-07-05
发文件上来,最好给一个例子
相似回答