{"id":188,"date":"2012-04-17T12:53:06","date_gmt":"2012-04-17T18:53:06","guid":{"rendered":"http:\/\/www.revivalprojects.com\/journal\/?p=188"},"modified":"2012-04-17T12:53:06","modified_gmt":"2012-04-17T18:53:06","slug":"excel-vba-copy-a-table-column-unique-data-to-another-table-column","status":"publish","type":"post","link":"http:\/\/revivalprojects.com\/journal\/2012\/04\/17\/excel-vba-copy-a-table-column-unique-data-to-another-table-column\/","title":{"rendered":"Excel VBA: Copy a Table Column Unique Data to Another Table Column"},"content":{"rendered":"<p>I have updated the functionality of my earlier post to only copy over unique values, then I added a sort on the values copied over.<\/p>\n<p><code><br \/>\nOption Compare Text<\/p>\n<p>'Copy a column from one Table to another<br \/>\nSub copyUnique()<\/p>\n<p>    'Delete current values prior to paste if values exist<br \/>\n    If Application.WorksheetFunction.CountA(Range(\"Table2[[Column1]]\")) <> 0 _<br \/>\n        Then Range(\"Table2[[Column1]]\").Delete<\/p>\n<p>    'Advanced filter for unique entries only<br \/>\n    Range(\"Table1[[#All],[Column3]]\").AdvancedFilter Action:=xlFilterInPlace, _<br \/>\n    Unique:=True<\/p>\n<p>    'Select desired column to copy with destination option<br \/>\n    Range(\"Table1[[Column3]]\").Copy _<br \/>\n        Destination:=Range(\"Table2[[Column1]]\")<\/p>\n<p>    'Remove Filter After Copy<br \/>\n    Range(\"Table1[[#Headers],[Column3]]\").Select<br \/>\n    ActiveSheet.ShowAllData<\/p>\n<p>    'Sort a table column A to Z<br \/>\n    Worksheets(\"Sheet2\").ListObjects(\"Column1\").Sort.SortFields.Clear<\/p>\n<p>    Worksheets(\"Sheet2\").ListObjects(\"Column1\").Sort.SortFields.Add _<br \/>\n        Key:=Range(\"Table2[[Column1]]\"), SortOn:=xlSortOnValues, _<br \/>\n        Order:=xlAscending, DataOption:=xlSortNormal<\/p>\n<p>    With Worksheets(\"Sheet2\").ListObjects(\"Column1\").Sort<br \/>\n        .Header = xlYes<br \/>\n        .MatchCase = False<br \/>\n        .Orientation = xlTopToBottom<br \/>\n        .SortMethod = xlPinYin<br \/>\n        .Apply<br \/>\n    End With<\/p>\n<p>End Sub<br \/>\n<\/code><\/p>\n<p>I am not certain if this is the best way to do it but the code is snappy and works for my needs.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have updated the functionality of my earlier post to only copy over unique values, then I added a sort on the values copied over. Option Compare Text &#8216;Copy a column from one Table to another Sub copyUnique() &#8216;Delete current values prior to paste if values exist If Application.WorksheetFunction.CountA(Range(&#8220;Table2[[Column1]]&#8221;)) 0 _ Then Range(&#8220;Table2[[Column1]]&#8221;).Delete &#8216;Advanced filter [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[3,9],"tags":[20,21,22,23,24,25],"class_list":["post-188","post","type-post","status-publish","format-standard","hentry","category-geeking","category-vba","tag-code","tag-copy","tag-excel","tag-function","tag-paste","tag-vba"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p4pNDf-32","jetpack_likes_enabled":true,"_links":{"self":[{"href":"http:\/\/revivalprojects.com\/journal\/wp-json\/wp\/v2\/posts\/188","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/revivalprojects.com\/journal\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/revivalprojects.com\/journal\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/revivalprojects.com\/journal\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/revivalprojects.com\/journal\/wp-json\/wp\/v2\/comments?post=188"}],"version-history":[{"count":0,"href":"http:\/\/revivalprojects.com\/journal\/wp-json\/wp\/v2\/posts\/188\/revisions"}],"wp:attachment":[{"href":"http:\/\/revivalprojects.com\/journal\/wp-json\/wp\/v2\/media?parent=188"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/revivalprojects.com\/journal\/wp-json\/wp\/v2\/categories?post=188"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/revivalprojects.com\/journal\/wp-json\/wp\/v2\/tags?post=188"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}