Option Explicit
'1. da modificare con il percorso del tuo pc e il nome del file da controllare
Const filecontr As String = "C:UsersuserDocumentsMagic BriefcaseEXCEL - VBAExcelvba.altervista.orgGiuseppe - confronto fra due file"
Const nomefile As String = "file da controllare.xlsx"
Sub confronto()
Dim rngA As Range, descrA As Range, colA As Range
Dim rngB As Range, descrB As Range, colB As Range
Dim c As Integer, presente As Boolean, r As Integer
Application.ScreenUpdating = False
Set rngA = [a1].CurrentRegion
'2. in questo caso controlla la colonna B; cambia la lettera in base alla tua tabella
Set colA = Range("b2:b" & rngA.Rows.Count)
Workbooks.Open Filename:=filecontr & nomefile
Set rngB = [a1].CurrentRegion
'3. anche qua cambia la lettera in base alla tua tabella, come sopra
Set colB = Range("b2:b" & rngB.Rows.Count)
Windows("file principale.xlsm").Activate
For Each descrB In colB
For Each descrA In colA
If descrB = descrA Then
presente = True
Exit For
End If
Next
If presente = False Then
descrB.EntireRow.Copy Destination:=Rows(r + rngA.Rows.Count + 1)
r = r + 1
End If
presente = False
Next
Windows(nomefile).Close
Application.ScreenUpdating = True
If r > 0 Then
MsgBox "Totale righe importate: " & r
Else
MsgBox "Nessun dato importato; tutte le descrizioni corrispondono"
End If
End Sub
|