Buongiorno,
la scorsa estate, grazie a questa discussione, avevo creato una formula che funzionava alla perfezione per le mie esigenze.
Sto provando ad adattarla ad un altro file ma non funziona e non riesco a capire perché. il mio file è così:
---------------A----------B-----------C--------------------------------D----------------------------------------E--------------
Riga 5: Nome file; VUOTA; Percorso cartella; Posizione nel file (es [File1]Foglio1'!B15:c35; Campo da cercare
in F5 ho la formula: =CERCA.VERT(E5;'Percorso cartella\Posizione nel file;2;0)
E il codice che ho inserito è:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim myRan As String, myCell As Range
'
myRan = "C5:D100" '<<< L'intervallo in cui saranno scritti i parametri
If Not Application.Intersect(Range(myRan), Target) Is Nothing Then
For Each myCell In Target
Cells(myCell.Row, "F").Formula = "=VLOOKUP(E" & myCell.Row & "," & Cells(myCell.Row, "C") & Cells(myCell.Row, "D") & ",3,0)"
Next myCell
End If
If Not Application.Intersect(Range(myRan), Target) Is Nothing Then
For Each myCell In Target
Cells(myCell.Row, "H").Formula = "=VLOOKUP(G" & myCell.Row & "," & Cells(myCell.Row, "C") & Cells(myCell.Row, "D") & ",3,0)"
Next myCell
End If
If Not Application.Intersect(Range(myRan), Target) Is Nothing Then
For Each myCell In Target
Cells(myCell.Row, "J").Formula = "=VLOOKUP(I" & myCell.Row & "," & Cells(myCell.Row, "C") & Cells(myCell.Row, "D") & ",3,0)"
Next myCell
End If
End SubIn H ho la stessa formula, che ricerca il valore presente in G e in J la formula che ricerca il valore presente in I.
Quando provo ad inserire in A6 il nome di un altro file e a trascinare le formule avviene: "Errore di run-time '1004': errore definito dall'applicazione o dall'oggetto" e cliccando Debug vedo che l'errore è dato dalla formula che comincia con "Cells(myCell.Row, "F")"...
Dato che non sono molto pratico di VBA non riesco proprio a capire dove sia l'errore.
Grazie a chi mi dovesse aiutare