如何筛选 excel中A列中相同数据对应B列中的不同数据

2025-04-04 14:12:27
推荐回答(3个)
回答1:

ALT+F11, 把如下代码放到Thisworkbook中,ALT+F8,执行ABC

Public Sub abc()
Dim A_i As Long, C_i As Long, flag As Boolean
A_i = 2
C_i = 1
Columns("A:B").Select
ActiveSheet.Sort.SortFields.Clear
ActiveSheet.Sort.SortFields.Add Key:=Range("A:A") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveSheet.Sort.SortFields.Add Key:=Range("B:B") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveSheet.Sort
.SetRange Range("A:B")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
If Cells(1, 1) = Cells(2, 1) And Cells(1, 2) <> Cells(1, 2) Then
Cells(C_i, 3) = Cells(A_i, 1)
Cells(C_i, 4) = Cells(A_i, 2)
C_i = C_i + 1
End If

Do While Cells(A_i, 1) <> ""

flag = True
If (Cells(A_i, 1) = Cells(A_i - 1, 1) And Cells(A_i, 2) = Cells(A_i - 1, 2)) Or (Cells(A_i, 1) = Cells(A_i + 1, 1) And Cells(A_i, 2) = Cells(A_i + 1, 2)) Or (Cells(A_i, 1) <> Cells(A_i - 1, 1) And Cells(A_i, 1) <> Cells(A_i + 1, 1)) Then
flag = False
End If

If flag Then
Cells(C_i, 3) = Cells(A_i, 1)
Cells(C_i, 4) = Cells(A_i, 2)
C_i = C_i + 1
End If

A_i = A_i + 1

Loop

End Sub

http://tieba.baidu.com/f?kz=750729252

回答2:

没看明白,LZ的数据应该有特殊的地方,最好多贴点数据或贴图

还有就是返回的不同数据需要怎样表示
-----------------------
好像比较复杂,太晚了,脑袋发昏,睡觉先

回答3:

我明白什么意思了 我明天上班研究下 现在太晚了。