{"id":211,"date":"2023-10-16T09:38:40","date_gmt":"2023-10-16T01:38:40","guid":{"rendered":"https:\/\/nnn.ink:368\/?p=211"},"modified":"2023-10-16T09:38:40","modified_gmt":"2023-10-16T01:38:40","slug":"%e6%95%b0%e6%8d%ae%e5%8e%bb%e9%87%8d-vba%e5%ad%97%e5%85%b8%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.biyuntang.com\/?p=211","title":{"rendered":"\u6570\u636e\u53bb\u91cd&#8212;&#8211;VBA\u5b57\u5178\u6cd5"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u5728Excel\u91cc\u9762\u6570\u636e\u53bb\u91cd\u65b9\u6cd5\u6bd4\u8f83\u591a\uff0c\u76ee\u524d\u7528\u7684\u6bd4\u8f83\u591a\u7684\u6709\uff1a<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">1.\u6570\u636e&#8211;\u7b5b\u9009&#8212;\u9ad8\u7ea7\u7b5b\u9009<\/h4>\n\n\n\n<h4 class=\"wp-block-heading\">2.\u6570\u636e\u900f\u89c6\u8868<\/h4>\n\n\n\n<h4 class=\"wp-block-heading\">\u4f46\u4ee5\u4e0a\u8fd9\u4e24\u79cd\u65b9\u6cd5\u90fd\u6709\u5c40\u9650\u6027\uff0c\u6bd4\u5982\u9700\u8981\u53bb\u91cd\u7684\u533a\u57df\u662f\u591a\u5217\u6570\u636e<\/h4>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u4ecb\u7ecd\u4e00\u79cd\u901a\u8fc7VBA\u7f16\u5199\u5b8f\u7a0b\u5e8f\u6765\u8fdb\u884c\u6570\u636e\u53bb\u91cd\uff0c\u53ef\u4ee5\u53bb\u91cd\u591a\u5217\u6570\u636e<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5148\u628a\u4ee3\u7801\u5448\u73b0\u51fa\u6765\uff0c\u518d\u8fdb\u884c\u89e3\u91ca\uff1a<em><\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\n\n<code>Sub \u5b57\u5178\u65b9\u6cd5()\n\n    Dim rng As Range       '\u5b9a\u4e49\u4e00\u4e2a\u533a\u57df\uff0c\u7528\u4e8e\u63a5\u6536\u9700\u8981\u53bb\u91cd\u7684\u5355\u5143\u683c\u533a\u57df\n\n    Set rng = Application.InputBox(\"\u8bf7\u6307\u5b9a\u53bb\u91cd\u533a\u57df\", \"\u6570\u636e\u6e90\u533a\u57df\", , , , , , 8)     '\u53ef\u4ee5\u662f\u4e00\u5217\uff0c\u4e5f\u53ef\u4ee5\u662f\u591a\u5217\n\n    If rng Is Nothing Then End         '\u5982\u679c\u6ca1\u6709\u9009\u62e9\u533a\u57df\uff0c\u5219\u9000\u51fa\uff0c\u6ce8\uff1a\u662fEnd\uff0c\u4e0d\u662fEnd IF\n\n\n\n    Dim arr    '\u5b9a\u4e49\u4e00\u4e2a\u6570\u7ec4\uff0c\u7528\u4e8e\u5b58\u50a8\u53bb\u91cd\u533a\u57df\u7684\u503c\n\n    arr = rng.value\n\n\n\n    Dim a\n\n    On Error Resume Next         '\u8fd9\u91cc\u9700\u8981\u5ffd\u7565\u9519\u8bef\uff0c\u540e\u9762\u6dfb\u52a0\u91cd\u590d\u952e\u503c\u4f1a\u5f15\u53d1\u9519\u8bef\n\n\n\n    Dim dic As Object    \n\n    Set dic = CreateObject(\"scripting.dictionary\")            '\u5f15\u7528\u5b57\u5178\u5bf9\u8c61\n\n\n\n    For Each a In arr\n\n        If Len(a) > 0 Then     \n\n            dic.Add CStr(a), \"\"     '\u5f80\u5b57\u5178\u91cc\u9762\u6dfb\u52a0\u952e\u503c\n\n        End If\n\n    Next a\n\n    Err.Clear\n\n\n\n    Set rng = Application.InputBox(\"\u8bf7\u6307\u5b9a\u7ed3\u679c\u5b58\u653e\u533a\u57df\uff0c\u5355\u4e2a\u5355\u5143\u683c\u5373\u53ef\", \"\u5b58\u653e\u533a\u57df\", , , , , , 8)\n\n\n\n    If Err &lt;> 0 Then End\n\n\n\n    rng(1).Resize(dic.Count, 1) = WorksheetFunction.Transpose(dic.Keys)         '\u5f80\u5355\u5143\u683c\u91cc\u9762\u5199\u5165\u53bb\u91cd\u540e\u7684\u6570\u636e\n\n\n\nEnd Sub<\/code>\n\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u91cc\u4e3b\u8981\u8fd0\u7528\u7684\u5b57\u5178\u7684\u952e\u503c\u552f\u4e00\u6027\uff0c\u5982\u679c\u5411\u5b57\u5178\u91cc\u9762\u6dfb\u52a0\u5df2\u7ecf\u5b58\u5728\u7684\u952e\uff0c\u5219\u4f1a\u5f15\u53d1\u9519\u8bef\uff0c\u6240\u4ee5\u4e2d\u95f4\u90e8\u5206\u9700\u8981\u5ffd\u7565\u9519\u8bef<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6570\u7ec4+\u5b57\u5178\u5728VBA\u91cc\u9762\u53ef\u4ee5\u63d0\u5347\u7a0b\u5e8f\u8fd0\u884c\u6548\u7387\uff0c\u5982\u60f3\u63d0\u5347VBA\u7a0b\u5e8f\u8fd0\u884c\u6548\u7387\uff0c\u53ef\u591a\u8fd0\u7528\u6570\u7ec4\u3001\u5b57\u5178<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728Excel\u91cc\u9762\u6570\u636e\u53bb\u91cd\u65b9\u6cd5\u6bd4\u8f83\u591a\uff0c\u76ee\u524d\u7528\u7684\u6bd4\u8f83\u591a\u7684\u6709\uff1a 1.\u6570\u636e&#8211;\u7b5b\u9009&#8212;\u9ad8\u7ea7\u7b5b\u9009 2.\u6570\u636e\u900f\u89c6\u8868 \u4f46\u4ee5\u4e0a\u8fd9\u4e24\u79cd\u65b9\u6cd5\u90fd\u6709\u5c40\u9650\u6027\uff0c\u6bd4\u5982\u9700\u8981\u53bb\u91cd\u7684\u533a\u57df\u662f\u591a\u5217\u6570\u636e \u4e0b\u9762\u4ecb\u7ecd\u4e00\u79cd\u901a\u8fc7V&#46;&#46;&#46;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"class_list":["post-211","post","type-post","status-publish","format-standard","hentry","category-vba"],"_links":{"self":[{"href":"https:\/\/www.biyuntang.com\/index.php?rest_route=\/wp\/v2\/posts\/211","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.biyuntang.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.biyuntang.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.biyuntang.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.biyuntang.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=211"}],"version-history":[{"count":1,"href":"https:\/\/www.biyuntang.com\/index.php?rest_route=\/wp\/v2\/posts\/211\/revisions"}],"predecessor-version":[{"id":212,"href":"https:\/\/www.biyuntang.com\/index.php?rest_route=\/wp\/v2\/posts\/211\/revisions\/212"}],"wp:attachment":[{"href":"https:\/\/www.biyuntang.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=211"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.biyuntang.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=211"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.biyuntang.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=211"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}