

- #How to use vlookup in excel for long data sets how to
- #How to use vlookup in excel for long data sets code
Sub VlookupFull()ĭim authorWs As Worksheet, detailsWs As Worksheetĭim authorsLastRow As Long, detailsLastRow As Long, x As Long Now open a module from Microsoft Visual Basic for Applications window, and write the following code.
#How to use vlookup in excel for long data sets how to
Read more: How to Find Value in Column Using VBA in ExcelĪgain, to keep the changes understandable, we have copied the dataset to the “Entire At Once” sheet.
#How to use vlookup in excel for long data sets code
In this section, we will see the VBA code to find the value for the entire data at once. Similar to this approach, fill the Birth Place column. Now select the next cell and press the shortcut key. We have found the result we were looking for. Save the code, then select the cell and press the shortcut key ( CTRL+SHIFT+J). In general, the lookup_array cell reference is B4:C10, which means row 4 column 2 to row 10 column 3, so we have set R4C2:R10C3 (from the “Details” sheet). Our lookup_value is at the 3 columns left to the selected cell that’s why we have written RC. The ActiveCell denotes which cell is going to be the selected one. We have only provided a single line of code within it. Once we have set the macro name and shortcut key then the outline of the SUB procedure has been created. Now in Microsoft Visual Basic for Applications, open the module for the Vlookup_shortcut macro and write the following code Sub Vlookup_shortcut()ĪctiveCell.FormulaR1C1 = "=VLOOKUP(RC,Details!R4C2:R10C3,2,0)" Here we have set Vlookup_shortcut as the macro name and CTRL+SHIFT+J as the shortcut.

Set the macro name and shortcut key to the respective fields. This will bring the Record Macro dialog box in front of you. Let’s proceed with the shortcut key.įrom the Developer tab select the Record Macro option. To execute the code, we need a button or shortcut key. Only selecting a cell will not trigger the code. Probably you have thought about how a mere selection will execute the code, absolutely correct. In our example, we will select a cell from the Birth Place column and our code will derive the birthplace for the author from that row. For this example, we have copied the data to the “Change Selection” sheet. To get rid of the problem we will see how to use VLOOKUP for a selected cell. That may seem irritating since we need to change the cell references every time before executing the code. In the earlier section, we have shown how to use VBA VLOOKUP for static changes. VBA VLOOKUP for a Selected cell in Another Worksheet Now change the respective cell references for the rest of the values to find the results.Ģ. Here we have changed the result containing cell reference from E4 to E5 and within VLOOKUP the lookup_value cell from B4 to B5. Now if you want to find the result for the second author from our list you need to modify the code a bit: change the respective cell references. We have found the birthplace of the author Arthur Conan Doyle. Now Run the code (for your convenience we have highlighted the Run button in the earlier image). Inside the VLOOKUP we have provided the author name as lookup_value where the “Details” sheet data was the lookup_array. Hope you have understood that the result will be derived from the VLOOKUP formula.

Within this sheet, using Range(“E4”), we have set the cell where we want to insert the result. Here we have written a SUB procedure, declared a variable ws that is a worksheet. Set ws = ThisWorkbook.Sheets("Static Changes") Now write the following code in the module. Here we have right-clicked at the project name which pops up the options, from there within Insert we found Module and clicked it. Now open Microsoft Visual Basic for Applications window pressing the ALT + F11 (Or you can explore the Developer tab and click Visual Basic). Hope you have noticed that this sheet name is “Static Changes”, we have copied the data from the “Data” sheet here to keep that sheet intact and understand the changes easily. We aim to find the birthplace for each writer that is listed in the “ Details” sheet. To show you examples, here we have introduced a Birth Place column to the author lists dataset. We can write the VBA VLOOKUP code in such a way that for every execution we need to change that manually. VLOOKUP From Different Worksheet.xlsm Excel VBA VLOOKUP to Find Values from Another Worksheet 1.
