{"id":68923,"date":"2005-09-20T15:29:00","date_gmt":"2005-09-20T15:29:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2005\/09\/20\/how-can-i-copy-column-c-of-one-worksheet-to-column-a-of-a-second-worksheet\/"},"modified":"2005-09-20T15:29:00","modified_gmt":"2005-09-20T15:29:00","slug":"how-can-i-copy-column-c-of-one-worksheet-to-column-a-of-a-second-worksheet","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-copy-column-c-of-one-worksheet-to-column-a-of-a-second-worksheet\/","title":{"rendered":"How Can I Copy Column C of One Worksheet to Column A of a Second Worksheet?"},"content":{"rendered":"<p><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\"> \n<P>Hey, Scripting Guy! How can I copy column C of one worksheet to column A of a second worksheet?<BR><BR>&#8212; JP<\/P><IMG border=\"0\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" height=\"5\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\"><A href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><IMG class=\"farGraphic\" title=\"Script Center\" border=\"0\" alt=\"Script Center\" align=\"right\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" height=\"288\"><\/A> \n<P>Hey, JP. Well, that\u2019s easy: you just open Excel, highlight column C, press Ctrl+C, put the cursor in column A1 of the second worksheet, and then press Ctrl+V. There you go, and thanks for your question.<\/P>\n<P>Oh, right: you wanted to know how to do this using a <I>script<\/I>. (What <I>were<\/I> we thinking?) But that\u2019s OK; it\u2019s just as easy to do this using a script as it is to do it manually:<\/P><PRE class=\"codeSample\">Set objExcel = CreateObject(&#8220;Excel.Application&#8221;)\nobjExcel.Visible = True\nSet objWorkbook = objExcel.Workbooks.Open(&#8220;C:\\Scripts\\Test.xls&#8221;)<\/p>\n<p>Set objWorksheet = objWorkbook.Worksheets(2)\nobjWorksheet.Activate<\/p>\n<p>Set objRange = objWorkSheet.Range(&#8220;C1&#8221;).EntireColumn\nobjRange.Copy<\/p>\n<p>Set objWorksheet = objWorkbook.Worksheets(1)\nobjWorksheet.Activate<\/p>\n<p>Set objRange = objWorkSheet.Range(&#8220;A1&#8221;)\nobjWorksheet.Paste(objRange)\n<\/PRE>\n<P>The script starts out by creating an instance of the <B>Excel.Application<\/B> object and then setting the <B>Visible<\/B> property to True; that gives us an instance of Excel that we can see on screen. We then use the <B>Open<\/B> method to open the file C:\\Scripts\\Test.xls. For this sample script, we\u2019re assuming that this file has at least two worksheets, and that there is data in column C of Sheet 2 that we want to copy.<\/P>\n<P>To do that we first create an object reference to Sheet 2 (the second worksheet in the <B>Worksheets<\/B> collection), and then call the <B>Activate<\/B> method to make this the active worksheet. That\u2019s what these two lines of code are for:<\/P><PRE class=\"codeSample\">Set objWorksheet = objWorkbook.Worksheets(2)\nobjWorksheet.Activate\n<\/PRE>\n<P>To select column C, we create an instance of the <B>Range<\/B> object, specifying cell C1 as the starting point, then using the <B>EntireColumn<\/B> property to select the rest of column C. That\u2019s what we do here:<\/P><PRE class=\"codeSample\">Set objRange = objWorkSheet.Range(&#8220;C1&#8221;).EntireColumn\n<\/PRE>\n<P>After we\u2019ve selected the column, we then call the <B>Copy<\/B> method to copy the data to the Clipboard.<\/P>\n<P>Now we need to switch to Sheet 1; we do that by creating an object reference to the first worksheet in the Worksheets collection and then calling the Activate method to make Sheet 1 the current worksheet. We then use this line of code to create a Range object that points to cell A1:<\/P><PRE class=\"codeSample\">Set objRange = objWorkSheet.Range(&#8220;A1&#8221;)\n<\/PRE>\n<P>Because we\u2019re pasting data there\u2019s no need to select the entire column; all we have to do is pick the starting cell and then call the <B>Paste<\/B> method, passing this method the object reference that indicates where we want the data pasted:<\/P><PRE class=\"codeSample\">objWorksheet.Paste(objRange)\n<\/PRE>\n<P>That should do the trick, and in fully automated fashion to boot. Like we always say (sometimes a bit prematurely): there you go, and thanks for your question. <\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I copy column C of one worksheet to column A of a second worksheet?&#8212; JP Hey, JP. Well, that\u2019s easy: you just open Excel, highlight column C, press Ctrl+C, put the cursor in column A1 of the second worksheet, and then press Ctrl+V. There you go, and thanks for your [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[710,711,48,49,3,5],"class_list":["post-68923","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-excel-spreadsheet","tag-excel-application","tag-microsoft-excel","tag-office","tag-scripting-guy","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! How can I copy column C of one worksheet to column A of a second worksheet?&#8212; JP Hey, JP. Well, that\u2019s easy: you just open Excel, highlight column C, press Ctrl+C, put the cursor in column A1 of the second worksheet, and then press Ctrl+V. There you go, and thanks for your [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/68923","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=68923"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/68923\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=68923"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=68923"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=68923"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}