Buon giorno a tutti
Utilizzo una Macro che tramite UserForm , mi permette di confrontare i dati presenti nella colonna A con quelli presenti nella colonna B e estrarre nella colonna C quelli che non sono presenti nella colonna B .
Esempio E1 1111 F1 1111
E2 2222 F2 2222
E3 3333 F3 3333
E4 4444 F4 5555
Tramite CommandButton , nella colonna G , nella Cella G1 avro' 4444 ( ...nel caso di piu' dati non presenti in colonna E i dati saranno ordinati da G1,G2,G3 eccetera ... )
Questa routine viene poi ripetuta per eseguire le stesse azioni nelle Colonne G , H , I
Le Routine sono 2 Private Sub cbCercaCodEliminati_Click() e
Private Sub cbCercaCodNuovi_Click()
Il range di dati e' di 4'000 righe
l'errore in oggetto avviene solo per la routine **Private Sub cbCercaCodEliminati_Click()**mentre l'altra esegue tutto il ciclo alla perfezione .
La cosa strana e' che i codici delle due routine , sono identici , cambiano solo i riferimenti alle colonne .
Questo il codice
Private Sub cbCercaCodEliminati_Click()
Dim rngA As Range
Dim rngB As Range
Dim arA As Variant
Dim arB As Variant
Dim sA As String
Dim vEle As Variant
Dim nStart As Single
Dim nStop As Single
nStart = Timer
Set rngA = Worksheets("Trova").Range(Cells(2, 4), Cells(Rows.Count, 4).End(xlUp))
Set rngB = Worksheets("Trova").Range(Cells(2, 5), Cells(Rows.Count, 5).End(xlUp))
arB = Application.Transpose(rngB.Value)
sA = "#" & Join(Application.Transpose(rngA.Value), "#") & "#"
For Each vEle In arB
sA = Replace(sA, "#" & vEle & "#", "#")
Next
sA = Mid(sA, 2, Len(sA) - 2) ' il Debug evidenzia in Giallo questa riga
arA = Split(sA, "#")
Set rngA = Worksheets("Trova").Range(Cells(2, 6), Cells(UBound(arA) + 2, 6))
rngA.Value = Application.Transpose(arA)
Set rngA = Nothing
Set rngB = Nothing
nStop = Timer
Debug.Print nStop - nStart
On Error GoTo XIT
Application.ScreenUpdating = False
XIT:
Application.ScreenUpdating = True
End Sub
Private Sub cbCercaCodNuovi_Click()
Dim rngA As Range
Dim rngB As Range
Dim arA As Variant
Dim arB As Variant
Dim sA As String
Dim vEle As Variant
Dim nStart As Single
Dim nStop As Single
nStart = Timer
Set rngA = Worksheets("Trova").Range(Cells(2, 7), Cells(Rows.Count, 7).End(xlUp))
Set rngB = Worksheets("Trova").Range(Cells(2, 8), Cells(Rows.Count, 8).End(xlUp))
arB = Application.Transpose(rngB.Value)
sA = "#" & Join(Application.Transpose(rngA.Value), "#") & "#"
For Each vEle In arB
sA = Replace(sA, "#" & vEle & "#", "#")
Next
sA = Mid(sA, 2, Len(sA) - 2)
arA = Split(sA, "#")
Set rngA = Worksheets("Trova").Range(Cells(2, 9), Cells(UBound(arA) + 2, 9))
rngA.Value = Application.Transpose(arA)
Set rngA = Nothing
Set rngB = Nothing
nStop = Timer
Debug.Print nStop - nStart
On Error GoTo XIT
Application.ScreenUpdating = False
XIT:
Application.ScreenUpdating = True
End Sub
Dove sbaglio ??? grazie per qualsiasi suggerimento Claudio P