{"id":169,"date":"2021-09-03T01:59:47","date_gmt":"2021-09-03T01:59:47","guid":{"rendered":"https:\/\/lgildv5i97.onrocket.site\/answers\/office-excel-search-box-and-copy-all-results-to-sheet-2-19013-html"},"modified":"2021-09-03T03:01:08","modified_gmt":"2021-09-03T03:01:08","slug":"office-excel-search-box-and-copy-all-results-to-sheet-2-19013-html","status":"publish","type":"question","link":"https:\/\/computing.net\/answers\/office\/excel-search-box-and-copy-all-results-to-sheet-2\/19013.html","title":{"rendered":"Solved Excel search box and copy all results to sheet # 2"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p>Good day..<\/p>\n<p>I&#8217;ve searched for an Excel macro that does the following :<\/p>\n<p>1. Press a button to open a search box<br \/>\n2. All results found to be copied to sheet # 2<\/p>\n<p>This would work similarly to a web search engine, where all found results appear. I&#8217;ve seen quite similar examples here in the community, but search parameters must be included beforehand in the macro contents. I need one that is flexible and allows me to use a search box for whatever text string I need to find in each case.<\/p>\n<p>Thanks a lot&#8230;<\/p>\n<p>I&#8217;ll let you know right up front that if I were a user, I would not like the way the following macro works, but it does what you&#8217;ve asked. I&#8217;ve look around for a Forms method that accepts both a text input from a user as well as a &#8220;radial button&#8221; choice, but as I said my Forms skills are minimal.<\/p>\n<p>I&#8217;ll keep looking&#8230;<\/p>\n<pre>Option Explicit\r\nSub FindCopy()\r\nDim myString, firstAddress As String\r\nDim nxtRw As Long\r\nDim c As Range\r\nDim tryAgain As Boolean\r\nDim mySize As String\r\nstartSearch:\r\n'Get input from user\r\n   myString = Application.InputBox(\"Enter A Search String\")\r\n'Exit if Cancelled\r\n     If myString = False Then Exit Sub\r\n'Force valid entry\r\n     If myString = \"\" Then\r\n       If MsgBox(\"The Search Field Can Not Be Left Blank\" _\r\n       &amp; vbLf &amp; vbLf &amp; \"Do You Want To Try Again?\", vbYesNo + vbQuestion) = _\r\n                        vbNo Then Exit Sub\r\n          GoTo startSearch\r\n     End If\r\n'Set lookat value based on Search String length\r\n    If MsgBox(\"Exact Match Only? \" &amp; vbCrLf &amp; vbCrLf &amp; _\r\n              \"Yes For Exact Match Of \" &amp; myString &amp; vbCrLf &amp; vbCrLf &amp; _\r\n              \"No For Any Match Of \" &amp; myString, vbYesNo + vbQuestion) = _\r\n                        vbYes Then mySize = xlWhole Else mySize = xlPart\r\n'Search entire sheet\r\n      With Sheets(1).Cells\r\n        Set c = .Find(myString, LookIn:=xlValues, LookAt:=mySize)\r\n'Perform Copy\/Paste\/FindNext if myString is found\r\n          If Not c Is Nothing Then\r\n             firstAddress = c.Address\r\n'Clear Sheet2\r\n  Sheets(2).Cells.ClearContents\r\n           Do\r\n'Find next empty Row in Sheet2 Column A\r\n             nxtRw = Sheets(2).Range(\"A\" &amp; Rows.Count).End(xlUp).Row + 1\r\n'Copy entire Row to next empty Row in Sheet 2\r\n               c.EntireRow.Copy _\r\n                 Destination:=Sheets(2).Range(\"A\" &amp; nxtRw)\r\n'Search again\r\n             Set c = .FindNext(c)\r\n            Loop While Not c Is Nothing And c.Address &lt;&gt; firstAddress\r\n          Else:\r\n            If MsgBox(\"Search String Not Found\" &amp; vbCrLf &amp; vbCrLf &amp; _\r\n                      \"Do You Want To Try Again?\", vbYesNo + vbQuestion) = _\r\n                        vbNo Then Exit Sub\r\n                GoTo startSearch\r\n          End If\r\n      End With\r\nEnd Sub<\/pre>\n<p><a href=\"http:\/\/www.computing.net\/howtos\/show\/posting-tables-with-the-pre-tag\/484.html\"><span><i><b>Click Here Before Posting Data or VBA Code &#8212;&gt; How To Post Data or Code.<\/b><\/i><\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","template":"","meta":{"inline_featured_image":false,"iawp_total_views":31},"question-category":[60],"question_tags":[],"class_list":["post-169","question","type-question","status-publish","hentry","question-category-dos"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question\/169","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=169"}],"wp:attachment":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/media?parent=169"}],"wp:term":[{"taxonomy":"question-category","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question-category?post=169"},{"taxonomy":"question_tags","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question_tags?post=169"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}