{"id":9869,"date":"2021-12-03T09:05:07","date_gmt":"2021-12-03T09:05:07","guid":{"rendered":"https:\/\/lgildv5i97.onrocket.site\/answers\/?post_type=question&#038;p=9869"},"modified":"2021-12-03T09:05:26","modified_gmt":"2021-12-03T09:05:26","slug":"solved-vba-to-add-vlookup-formula-to-last-row","status":"publish","type":"question","link":"https:\/\/computing.net\/answers\/office\/vba-to-add-vlookup-formula-to-last-row\/20010.html","title":{"rendered":"Solved VBA To Add VLOOKUP Formula To Last Row"},"content":{"rendered":"<p>Hi,<\/p>\n<p>I would like to add a formula for a VLOOKUP to a column to the last row. This is the actual formula:<\/p>\n<pre>=VLOOKUP(C4,'Open Job Query'!B:L,9,FALSE)<\/pre>\n<p>Tried adding to the below formula but failing miserably ;(<\/p>\n<p>&nbsp;<\/p>\n<pre>Sub CopyColumns()\r\n\r\n'Clear range on Datasheet to Update Timberline sheet\r\n    Sheets(\"Datasheet to Update Timberline\").Range(\"A4:E5000\").ClearContents\r\n\r\nDim lastrow As Long, erow As Long, i As Long\r\n\r\nlastrow = Sheet2.Cells(Rows.Count, 1).End(xlUp).Row\r\nFor i = 6 To lastrow\r\n\r\nerow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row\r\n    \r\nSheet2.Cells(i, 8).Copy\r\n    Worksheets(\"Datasheet to Update Timberline\").Cells(erow, 1).PasteSpecial Paste:=xlPasteValues\r\n\r\nSheet2.Cells(i, 4).Copy\r\n    Worksheets(\"Datasheet to Update Timberline\").Cells(erow, 2).PasteSpecial Paste:=xlPasteValues\r\n\r\nSheet2.Cells(i, 2).Copy\r\n    Worksheets(\"Datasheet to Update Timberline\").Cells(erow, 3).PasteSpecial Paste:=xlPasteValues\r\n\r\nSheet2.Cells(i, 3).Copy\r\n    Worksheets(\"Datasheet to Update Timberline\").Cells(erow, 4).PasteSpecial Paste:=xlPasteValues\r\n    \r\n\r\n&lt;b&gt;Sheets(\"Datasheet to Update Timberline\").Range(\"E4\" &amp; erow + 1).Formula = \"=VLOOKUP(C4:C\" &amp; erow &amp; \",\"Sheets(\"Open Job Query\").Range(\"B:L\",9,FALSE)\"&lt;\/b&gt;\r\n\r\nNext i\r\n\r\nApplication.CutCopyMode = False\r\nSheet1.Columns.AutoFit\r\nRange(\"A1\").Select\r\n\r\nEnd Sub<\/pre>\n<p>Any help is greatly appreciated!<\/p>\n<p>Thank you,<br \/>\nSandi<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"inline_featured_image":false,"iawp_total_views":3},"question-category":[53],"question_tags":[],"class_list":["post-9869","question","type-question","status-publish","hentry","question-category-office"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question\/9869","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question"}],"about":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/types\/question"}],"author":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/comments?post=9869"}],"wp:attachment":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/media?parent=9869"}],"wp:term":[{"taxonomy":"question-category","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question-category?post=9869"},{"taxonomy":"question_tags","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question_tags?post=9869"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}