Process (Code debug) VBA lookup function

Aliq2014

New Member
Joined
Sep 10, 2014
Messages
46
Hi, I’m currently working on a macro using the vlookup function.</SPAN>

Vlookup formlula:</SPAN>
Workbooks: A)Parking_Template.xlsm – contains 55 columns (A,B….AJ……BC)</SPAN></SPAN>
B) EFMA_Template.xlsm- contains 8 columns (A,B</SPAN>,C,D,E,F,G</SPAN>,H</SPAN>)</SPAN>
Formula: </SPAN>"=VLOOKUP(AJ:AJ,'[EFMS _Template.xlsm]Sheet1'!$B:$H,6,FALSE)".</SPAN>

The formula looks at column “AJ” which is the lookup value, table array EFMS _Template.xlsm]Sheet1'!$B:$H, index to return 6, exact match.
</SPAN>
I would like to automate the process by coding a macro that uses the vlookup function.


Someone already assisted me a code snippet and I modified:</SPAN>

  1. Sub FindVal()</SPAN>
  2. Dim x, lRow As Long</SPAN>
  3. lRow = Cells(Rows.Count, 1).End(xlUp).Row 'to find the last row</SPAN>
  4. On Error Resume Next</SPAN>
  5. For x = 1 To lRow</SPAN>
  6. Cells(x, 2) = Application.WorksheetFunction.VLOOKUP(Cells(x, 1), Workbooks("EFMA_template.xlsm").Worksheets("Sheet1").Range("B:H"), 6, False)</SPAN>
  7. Next x</SPAN>
  8. End Sub</SPAN>
</SPAN>

I'm having an issue understanding the loop. The above code is not working correctly. Im new to programming and vba. Would someone please help me troubleshoot this issue?

Thanks..
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Forum statistics

Threads
1,225,072
Messages
6,182,699
Members
453,132
Latest member
nsnodgrass73

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