Private Sub CommandButton1_Click()
Dim iRow As Long
Dim eRow As Long
Dim trova, cerca, confronta, calcolo As Worksheet
Dim continueValue As Integer
Dim stopValue As Integer
Dim changeValue As Integer
Set trova = Worksheets("Elenco1")
Set cerca = Worksheets("Elenco2")
Set calcolo = Worksheets("Calcolo")
Set confronta = Worksheets("Comparison")
' nel codice sottostante mi segnala errore
Set eRow = trova.Cells(1, 8).End(xlDown).Offset(1).Row
Set iRow = cerca.Cells(1, 4).End(xlDown).Offset(1).Row
'qui mi si attiva un ciclo loop, che continua ad operare finché non è stata effettuata la ricerca per tutti i record dell'Elenco2
Do While calcolo.Cells(1, 12).Value = 0
' e qui mi avvia un secondo ciclo loop nidificato che continua finché per ogni record dell'elenco 2 ha effettuato il confronto in tutti i record dell'elenco 1
Do While calcolo.Cells(1, 11).Value = 0
cerca.Select
Range(Cells(iRow, 1), Cells(iRow, 3)).Select
Selection.Copy
confronta.Select
Range(Cells(2, 1), Cells(2, 3)).Select
Selection.PasteSpecial Paste:=xlPasteValues
Set rigaVer = confronta.Range("A2:C2")
Set nOcO = Cells(4, 1)
Set NO = Cells(4, 2)
Set cO = Cells(4, 3)
'nome_cognome, nome e cognome vengono separati e disposti in colonna
rigaVer.Select
Selection.Copy
rigaVer.Select
Application.CutCopyMode = False
Selection.Copy
nOcO.Select
Selection.PasteSpecial Transpose:=True
Application.CutCopyMode = False
Selection.TextToColumns Destination:=nOcO, DataType:=xlDelimited, ConsecutiveDelimiter:=True, Tab:=False, Comma:=False, Space:=True, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1)), TrailingMinusNumbers:=True
NO.Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
nOcO.Select
Selection.End(xlDown).Select
Range("A7").Select
Selection.PasteSpecial Transpose:=True
Range("A8").Select
Selection.End(xlUp).Select
NO.Select
Range(Selection, Selection.End(xlToRight)).Select
Application.CutCopyMode = False
Selection.ClearContents
Range("B5").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Range("A5").Select
Selection.End(xlDown).Select
Range("A9").Select
Selection.PasteSpecial Transpose:=True
Range("A5").Select
Selection.End(xlUp).Select
Range("B5").Select
Range(Selection, Selection.End(xlToRight)).Select
Application.CutCopyMode = False
Selection.ClearContents
Range("A5").Select
Selection.End(xlUp).Select
Range("B6").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Range("A6").Select
Selection.End(xlDown).Select
Range("A9").Select
Selection.PasteSpecial Transpose:=True
Application.CutCopyMode = False
Selection.End(xlUp).Select
Range("B6").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.ClearContents
Range("A6").Select
'ora vengono rimossi i duplicati
Range(nOcO, Cells(999, 1)).RemoveDuplicates Columns:=1, Header:=xlNo
Dim Intervallo As Range
Dim Righe, R
Set Intervallo = Range(nOcO, Cells(999, 1))
'viene individuata la prima scheda dell'intervallo con le email da confrontare
trova.Select
Range(Cells(eRow, 3), Cells(eRow, 5)).Select
Selection.Copy
confronta.Select
Range(Cells(2, 8), Cells(2, 10)).Select
Selection.PasteSpecial Paste:=xlPasteValues
Set rigaVer2 = confronta.Range("H2:J2")
Set nOcO2 = Cells(4, 8)
Set nO2 = Cells(4, 9)
Set cO2 = Cells(4, 10)
'spostate nelle colonne
rigaVer2.Select
Selection.Copy
rigaVer2.Select
Application.CutCopyMode = False
Selection.Copy
nOcO2.Select
Selection.PasteSpecial Paste:=xlPasteAll, Transpose:=True
Application.CutCopyMode = False
nOcO2.Select
Selection.TextToColumns Destination:=nOcO2, Space:=True, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1)), TrailingMinusNumbers:=True
nO2.Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
nOcO2.Select
Selection.End(xlDown).Select
Range("H7").Select
Selection.PasteSpecial Transpose:=True
Range("H8").Select
Selection.End(xlUp).Select
nO2.Select
Range(Selection, Selection.End(xlToRight)).Select
Application.CutCopyMode = False
Selection.ClearContents
Range("I5").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Range("H5").Select
Selection.End(xlDown).Select
Range("H9").Select
Selection.PasteSpecial Transpose:=True
Range("H5").Select
Selection.End(xlUp).Select
Range("I5").Select
Range(Selection, Selection.End(xlToRight)).Select
Application.CutCopyMode = False
Selection.ClearContents
Range("H5").Select
Selection.End(xlUp).Select
Range("I6").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Range("H6").Select
Selection.End(xlDown).Select
Range("H9").Select
Selection.PasteSpecial Transpose:=True
Application.CutCopyMode = False
Selection.End(xlUp).Select
Range("I6").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.ClearContents
Range("H6").Select
'ora vengono rimossi i duplicati
Range(nOcO2, Cells(999, 8)).RemoveDuplicates Columns:=1, Header:=xlNo
Dim Intervallo2 As Range
Set Intervallo2 = Range(nOcO2, Cells(999, 8))
If Cells(5, 12).Value > "0,85" Then
confronta.Cells(2, 12).Select
Selection.Copy
cerca.Cells(confronta.Cells(2, 4).Value, 4).Select
Selection.PasteSpecial Transpose:=True
Exit Do
Else
cerca.Cells(confronta.Cells(1, 4).Value, 4).Value = NO
End If
eRow = eRow + 1
Loop
iRow = iRow + 1
Loop
End Sub |