Vlookup vba code

fabiogiallo

New Member
Joined
Mar 1, 2018
Messages
6
Buongiorno,

ho una funzione vlookup estesa a tutta una colonna, usando il seguente codice VBA

ActiveCell.FormulaR1C1 = "=VLOOKUP(Sheet2!RC[-1],R1C1:R109C19,7,FALSE)"
Selection.AutoFill Destination:=Range("B2:B15693")

viene trascritta solo la classica formula in tutte le celle della colonna.

Potreste suggerirmi un codice che esegue la stessa funzione senza scrivere materialmente la formula nel foglio excel (ne risulterebbe appensantito).

Grazie.
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Puoi utilizzare vlookup nel codice tramite un oggetto applicazione o valutare, ma ecco un semplice esempio di dizionario di scripting:


Excel 2010
ABCDEFGHIJ
1NameNumberNameNumber
2WQ6
3QW4
4AE2
5FR1
6IT8
7YY7
8U4
9I0
10O2
11P1
12A6
13S3
14D9
15F4
Sheet4


Code:
Sub test5()
Dim i%, lr1%, lr2%, d As Object
Set d = CreateObject("scripting.dictionary")
lr1 = Cells(Rows.Count, 5).End(xlUp).Row
lr2 = Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To lr1
d(Cells(i, 5).Value) = Cells(i, 10).Value
Next
For i = 2 To lr2
Cells(i, 2).Value = d(Cells(i, 1).Value)
Next
End Sub


Excel 2010
ABCDEFGHIJ
1NameNumberNameNumber
2W4Q6
3Q6W4
4A6E2
5F4R1
6I0T8
7Y7Y7
8U4
9I0
10O2
11P1
12A6
13S3
14D9
15F4
Sheet4
 
Upvote 0
Mi pare che invece di inserire la formula in 15mila righe vorresti inserire il risultato.
Non ho verificato quanto postato da SheetSpread, ma se il problema si presenta su "molte colonne" potresti essere in difficolta' a riprodurre la soluzione "dictionary based" che ti ha proposto.
Io piu' semplicemente direi:
-inserisci la formula con le istruzioni che hai
-poi copia il valore ottenuto e fai IncollaSpeciale /Valori

Cioe':
Code:
ActiveCell.FormulaR1C1 = "=VLOOKUP(Sheet2!RC[-1],R1C1:R109C19,7,FALSE)"
Selection.AutoFill Destination:=Range("B2:B15693")
Range("B2:B15693").Value=Range("B2:B15693").Value
Ciao
 
Upvote 0
se il problema si presenta su "molte colonne" potresti essere in difficolta' a riprodurre la soluzione "dictionary based" che ti ha proposto.
Io piu' semplicemente direi:
-inserisci la formula con le istruzioni che hai
-poi copia il valore ottenuto e fai IncollaSpeciale /Valori

Gli elementi del dizionario possono essere anche array o l'intero intervallo può essere passato a un array 2D per ricerche più veloci. Ma anche la tua soluzione è buona.
 
Upvote 0

Forum statistics

Threads
1,213,557
Messages
6,114,287
Members
448,562
Latest member
Flashbond

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top