Olá Geneci,
Geneci,
Primeiro uma correção:
No início da planilha troque o “B” por “D” na linha abaixo:
For Indx = 1 To Range("B" & Rows.Count).End(xlUp).Row
Isso não fez diferença nos testes porque ambas as colunas tem 50 linhas, mas quando a quantidade de linhas das colunas for diferentes, vai fazer diferença.
Segue abaixo a macro já com classificação:
Código: Selecionar todosSub ApagaPares()
'Apaga pares de números entre as colunas B e D
Atual = ActiveCell.Address
Range("B1:B" & Range("B" & Rows.Count).End(xlUp).Row).Select
Msg = "Valore(s) da coluna D, não encontrado(s) na coluna B." & vbCrLf & vbCrLf: MsgFlag = 0
For Indx = 1 To Range("D" & Rows.Count).End(xlUp).Row
Alvo = Range("D" & Indx).Value
On Error Resume Next
Aqui = Selection.Find(What:=Alvo, After:=ActiveCell, LookIn:=xlValues, LookAt:=xlWhole, _
SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Row
If Err = 0 Then
Range("B" & Aqui & ",D" & Indx).ClearContents
Else
MsgFlag = 1
Msg = Msg & "Valor " & Alvo & ", linha " & Indx & vbCrLf
End If
Next
For Aux1 = 1 To 2
If Aux1 = 1 Then Col = "B"
If Aux1 = 2 Then Col = "D"
Range(Col & "1:" & Col & Range(Col & Rows.Count).End(xlUp).Row).Select
Selection.Sort Key1:=Range(Col & "1"), Order1:=xlAscending, _
Header:=xlNo, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Next
Range(Atual).Select
If MsgFlag = 1 Then MsgBox Msg
End Sub
Acho que com a classificação, e todos os números ficando juntos, não há mais a necessidade da mensagem de números não localizados.
A macro abaixo está sem a mensagem:
Código: Selecionar todosSub ApagaPares()
'Apaga pares de números entre as colunas B e D
Atual = ActiveCell.Address
Range("B1:B" & Range("B" & Rows.Count).End(xlUp).Row).Select
For Indx = 1 To Range("D" & Rows.Count).End(xlUp).Row
Alvo = Range("D" & Indx).Value
On Error Resume Next
Aqui = Selection.Find(What:=Alvo, After:=ActiveCell, LookIn:=xlValues, LookAt:=xlWhole, _
SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Row
If Err = 0 Then
Range("B" & Aqui & ",D" & Indx).ClearContents
End If
Next
For Aux1 = 1 To 2
If Aux1 = 1 Then Col = "B"
If Aux1 = 2 Then Col = "D"
Range(Col & "1:" & Col & Range(Col & Rows.Count).End(xlUp).Row).Select
Selection.Sort Key1:=Range(Col & "1"), Order1:=xlAscending, _
Header:=xlNo, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Next
Range(Atual).Select
End Sub