{"id":600,"date":"2025-03-21T02:33:35","date_gmt":"2025-03-20T17:33:35","guid":{"rendered":"https:\/\/hajidai.com\/excel\/2025\/03\/excel%e3%83%9e%e3%82%b9%e3%82%bf%e3%83%bc%e3%81%b8%e3%81%ae%e9%81%93-%e4%b8%8a%e7%b4%9a%e8%80%85%e3%81%ae%e3%81%9f%e3%82%81%e3%81%ae5%e3%81%a4%e3%81%ae%e5%ae%9f%e8%b7%b5%e7%9a%84vba%e3%83%86%e3%82%af\/"},"modified":"2025-03-21T02:33:35","modified_gmt":"2025-03-20T17:33:35","slug":"excel%e3%83%9e%e3%82%b9%e3%82%bf%e3%83%bc%e3%81%b8%e3%81%ae%e9%81%93-%e4%b8%8a%e7%b4%9a%e8%80%85%e3%81%ae%e3%81%9f%e3%82%81%e3%81%ae5%e3%81%a4%e3%81%ae%e5%ae%9f%e8%b7%b5%e7%9a%84vba%e3%83%86%e3%82%af","status":"publish","type":"post","link":"https:\/\/hajidai.com\/excel\/2025\/03\/excel%e3%83%9e%e3%82%b9%e3%82%bf%e3%83%bc%e3%81%b8%e3%81%ae%e9%81%93-%e4%b8%8a%e7%b4%9a%e8%80%85%e3%81%ae%e3%81%9f%e3%82%81%e3%81%ae5%e3%81%a4%e3%81%ae%e5%ae%9f%e8%b7%b5%e7%9a%84vba%e3%83%86%e3%82%af\/","title":{"rendered":"Excel\u30de\u30b9\u30bf\u30fc\u3078\u306e\u9053: \u4e0a\u7d1a\u8005\u306e\u305f\u3081\u306e5\u3064\u306e\u5b9f\u8df5\u7684VBA\u30c6\u30af\u30cb\u30c3\u30af"},"content":{"rendered":"<h2>\u4e0a\u7d1a\u8005\u5411\u3051VBA\u30b3\u30fc\u30c9\u6700\u9069\u5316\u3068\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u30c1\u30e5\u30fc\u30cb\u30f3\u30b0\uff1a\u52b9\u7387\u7684\u306aExcel \u30de\u30af\u30ed\u306e\u6975\u610f<\/h2>\n<p>Excel\u3092\u4f7f\u3044\u3053\u306a\u3057\u3066\u3082\u3063\u3068\u697d\u3092\u3057\u305f\u3044\u3001\u696d\u52d9\u3092\u52b9\u7387\u5316\u3057\u305f\u3044\u4e0a\u7d1a\u8005\u306e\u65b9\u306b\u3001\u3059\u3050\u306b\u8a66\u305b\u308b\u4fbf\u5229\u306a\u30de\u30af\u30ed\u30b3\u30fc\u30c9\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u306f\u3001\u9078\u629e\u3057\u305f\u30bb\u30eb\u7bc4\u56f2\u5185\u306e\u91cd\u8907\u30c7\u30fc\u30bf\u3092\u524a\u9664\u3057\u3001\u30e6\u30cb\u30fc\u30af\u306a\u5024\u306e\u307f\u3092\u6b8b\u3059\u30de\u30af\u30ed\u3067\u3059\u3002<\/p>\n<p>&#8220;`vba<br \/>\nSub RemoveDuplicates()<br \/>\n    Dim rng As Range<br \/>\n    Set rng = Selection<br \/>\n    rng.RemoveDuplicates Columns:=1, Header:=xlNo<br \/>\nEnd Sub<br \/>\n&#8220;`<\/p>\n<p>\u3053\u306e\u30de\u30af\u30ed\u3092\u5b9f\u884c\u3059\u308b\u3068\u3001\u9078\u629e\u3057\u305f\u7bc4\u56f2\u5185\u306e\u91cd\u8907\u30c7\u30fc\u30bf\u304c\u77ac\u6642\u306b\u524a\u9664\u3055\u308c\u307e\u3059\u3002\u5927\u91cf\u306e\u30c7\u30fc\u30bf\u3092\u6271\u3046\u969b\u306b\u975e\u5e38\u306b\u4fbf\u5229\u3067\u3059\u3002<\/p>\n<h3>1. VBA\u30b3\u30fc\u30c9\u306e\u6700\u9069\u5316\u30c6\u30af\u30cb\u30c3\u30af<\/h3>\n<p>Excel \u30de\u30af\u30ed\u306e\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u5411\u4e0a\u3055\u305b\u308b\u306b\u306f\u3001\u30b3\u30fc\u30c9\u306e\u6700\u9069\u5316\u304c\u4e0d\u53ef\u6b20\u3067\u3059\u3002\u4ee5\u4e0b\u306e\u30dd\u30a4\u30f3\u30c8\u306b\u6ce8\u76ee\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<h4>\u5909\u6570\u306e\u5ba3\u8a00\u3068\u578b\u6307\u5b9a<\/h4>\n<p>\u5909\u6570\u3092\u9069\u5207\u306b\u5ba3\u8a00\u3057\u3001\u660e\u793a\u7684\u306b\u578b\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u3067\u3001VBA\u306e\u5b9f\u884c\u901f\u5ea6\u304c\u5411\u4e0a\u3057\u307e\u3059\u3002\u4f8b\u3048\u3070\u3001`Dim i As Long`\u306e\u3088\u3046\u306b\u5909\u6570\u306e\u578b\u3092\u6307\u5b9a\u3059\u308b\u3068\u3001VBA\u30a8\u30f3\u30b8\u30f3\u304c\u5909\u6570\u306e\u578b\u3092\u63a8\u6e2c\u3059\u308b\u5fc5\u8981\u304c\u306a\u304f\u306a\u308a\u3001\u51e6\u7406\u304c\u9ad8\u901f\u5316\u3055\u308c\u307e\u3059\u3002<\/p>\n<h4>\u30eb\u30fc\u30d7\u306e\u6700\u9069\u5316<\/h4>\n<p>For Each\u30eb\u30fc\u30d7\u306f\u4fbf\u5229\u3067\u3059\u304c\u3001\u5927\u91cf\u306e\u30c7\u30fc\u30bf\u3092\u51e6\u7406\u3059\u308b\u969b\u306b\u306f\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u304c\u4f4e\u4e0b\u3059\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002\u4ee3\u308f\u308a\u306b\u3001For&#8230;Next\u30eb\u30fc\u30d7\u3092\u4f7f\u7528\u3057\u3001\u30b9\u30c6\u30c3\u30d7\u30b5\u30a4\u30ba\u3092\u9069\u5207\u306b\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u3067\u3001\u51e6\u7406\u901f\u5ea6\u3092\u5927\u5e45\u306b\u5411\u4e0a\u3055\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<h4>\u753b\u9762\u66f4\u65b0\u306e\u5236\u5fa1<\/h4>\n<p>\u30de\u30af\u30ed\u5b9f\u884c\u4e2d\u306e\u753b\u9762\u66f4\u65b0\u3092\u4e00\u6642\u7684\u306b\u505c\u6b62\u3059\u308b\u3053\u3068\u3067\u3001\u51e6\u7406\u901f\u5ea6\u3092\u5411\u4e0a\u3055\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u4f7f\u7528\u3057\u3066\u3001\u753b\u9762\u66f4\u65b0\u3092\u5236\u5fa1\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>&#8220;`vba<br \/>\nApplication.ScreenUpdating = False<br \/>\n&#8216; \u30de\u30af\u30ed\u306e\u30e1\u30a4\u30f3\u51e6\u7406<br \/>\nApplication.ScreenUpdating = True<br \/>\n&#8220;`<\/p>\n<h3>2. \u30e1\u30e2\u30ea\u4f7f\u7528\u91cf\u306e\u6700\u9069\u5316<\/h3>\n<p>Excel \u30de\u30af\u30ed\u306e\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u5411\u4e0a\u3055\u305b\u308b\u3082\u3046\u4e00\u3064\u306e\u91cd\u8981\u306a\u8981\u7d20\u306f\u3001\u30e1\u30e2\u30ea\u4f7f\u7528\u91cf\u306e\u6700\u9069\u5316\u3067\u3059\u3002<\/p>\n<h4>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u5909\u6570\u306e\u89e3\u653e<\/h4>\n<p>\u4f7f\u7528\u6e08\u307f\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u5909\u6570\u306f\u3001\u660e\u793a\u7684\u306b\u89e3\u653e\u3059\u308b\u3053\u3068\u3092\u304a\u52e7\u3081\u3057\u307e\u3059\u3002\u7279\u306b\u5927\u898f\u6a21\u306a\u30de\u30af\u30ed\u3067\u306f\u3001\u30e1\u30e2\u30ea\u30ea\u30fc\u30af\u3092\u9632\u3050\u305f\u3081\u306b\u91cd\u8981\u3067\u3059\u3002<\/p>\n<p>&#8220;`vba<br \/>\nSet obj = Nothing<br \/>\n&#8220;`<\/p>\n<h4>\u914d\u5217\u306e\u6d3b\u7528<\/h4>\n<p>\u5927\u91cf\u306e\u30c7\u30fc\u30bf\u3092\u51e6\u7406\u3059\u308b\u969b\u306f\u3001\u30bb\u30eb\u7bc4\u56f2\u3092\u914d\u5217\u306b\u8aad\u307f\u8fbc\u3093\u3067\u51e6\u7406\u3092\u884c\u3044\u3001\u6700\u5f8c\u306b\u7d50\u679c\u3092\u30b7\u30fc\u30c8\u306b\u66f8\u304d\u623b\u3059\u65b9\u6cd5\u304c\u52b9\u7387\u7684\u3067\u3059\u3002\u3053\u308c\u306b\u3088\u308a\u3001\u30ef\u30fc\u30af\u30b7\u30fc\u30c8\u3068\u306e\u983b\u7e41\u306a\u3084\u308a\u53d6\u308a\u3092\u6e1b\u3089\u3057\u3001\u51e6\u7406\u901f\u5ea6\u3092\u5927\u5e45\u306b\u5411\u4e0a\u3055\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<h4>\u4e0d\u8981\u306a\u30ef\u30fc\u30af\u30b7\u30fc\u30c8\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u524a\u9664<\/h4>\n<p>\u4f7f\u7528\u3057\u3066\u3044\u306a\u3044\u30ef\u30fc\u30af\u30b7\u30fc\u30c8\u3084\u30b0\u30e9\u30d5\u306f\u524a\u9664\u3057\u307e\u3057\u3087\u3046\u3002\u3053\u308c\u3089\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f\u30e1\u30e2\u30ea\u3092\u6d88\u8cbb\u3059\u308b\u305f\u3081\u3001\u5fc5\u8981\u306e\u306a\u3044\u3082\u306e\u306f\u7a4d\u6975\u7684\u306b\u524a\u9664\u3059\u308b\u3053\u3068\u3067\u3001\u30de\u30af\u30ed\u306e\u5b9f\u884c\u901f\u5ea6\u304c\u5411\u4e0a\u3057\u307e\u3059\u3002<\/p>\n<h3>3. \u30a8\u30e9\u30fc\u51e6\u7406\u3068\u30c7\u30d0\u30c3\u30b0\u6280\u8853<\/h3>\n<p>\u52b9\u7387\u7684\u306aExcel \u30de\u30af\u30ed\u958b\u767a\u306b\u306f\u3001\u9069\u5207\u306a\u30a8\u30e9\u30fc\u51e6\u7406\u3068\u30c7\u30d0\u30c3\u30b0\u6280\u8853\u3082\u6b20\u304b\u305b\u307e\u305b\u3093\u3002<\/p>\n<h4>\u30a8\u30e9\u30fc\u51e6\u7406\u306e\u5b9f\u88c5<\/h4>\n<p>On Error GoTo\u6587\u3092\u4f7f\u7528\u3057\u3066\u3001\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u305f\u969b\u306e\u51e6\u7406\u3092\u6307\u5b9a\u3057\u307e\u3057\u3087\u3046\u3002\u3053\u308c\u306b\u3088\u308a\u3001\u30de\u30af\u30ed\u306e\u5b9f\u884c\u4e2d\u306b\u4e88\u671f\u305b\u306c\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u305f\u5834\u5408\u3067\u3082\u3001\u9069\u5207\u306b\u5bfe\u5fdc\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>&#8220;`vba<br \/>\nOn Error GoTo ErrorHandler<br \/>\n&#8216; \u30de\u30af\u30ed\u306e\u30e1\u30a4\u30f3\u51e6\u7406<br \/>\nExit Sub<\/p>\n<p>ErrorHandler:<br \/>\nMsgBox &#8220;\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3057\u305f: &#8221; &#038; Err.Description<br \/>\n&#8220;`<\/p>\n<h4>\u30c7\u30d0\u30c3\u30b0\u6280\u8853\u306e\u6d3b\u7528<\/h4>\n<p>VBA\u30a8\u30c7\u30a3\u30bf\u306e\u30c7\u30d0\u30c3\u30b0\u6a5f\u80fd\u3092\u6d3b\u7528\u3057\u307e\u3057\u3087\u3046\u3002\u30d6\u30ec\u30fc\u30af\u30dd\u30a4\u30f3\u30c8\u3092\u8a2d\u5b9a\u3057\u3001\u30b9\u30c6\u30c3\u30d7\u5b9f\u884c\u3092\u884c\u3046\u3053\u3068\u3067\u3001\u30b3\u30fc\u30c9\u306e\u52d5\u4f5c\u3092\u8a73\u7d30\u306b\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002\u307e\u305f\u3001Immediate\u30a6\u30a3\u30f3\u30c9\u30a6\u3092\u4f7f\u7528\u3057\u3066\u3001\u5909\u6570\u306e\u5024\u3092\u78ba\u8a8d\u3057\u305f\u308a\u3001\u7c21\u5358\u306a\u30b3\u30fc\u30c9\u3092\u8a66\u3057\u305f\u308a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<h4>\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u6e2c\u5b9a<\/h4>\n<p>\u30de\u30af\u30ed\u306e\u5b9f\u884c\u6642\u9593\u3092\u6e2c\u5b9a\u3059\u308b\u3053\u3068\u3067\u3001\u6700\u9069\u5316\u306e\u52b9\u679c\u3092\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30b3\u30fc\u30c9\u3092\u4f7f\u7528\u3057\u3066\u3001\u51e6\u7406\u6642\u9593\u3092\u8a08\u6e2c\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>&#8220;`vba<br \/>\nDim startTime As Double<br \/>\nstartTime = Timer<br \/>\n&#8216; \u30de\u30af\u30ed\u306e\u30e1\u30a4\u30f3\u51e6\u7406<br \/>\nDebug.Print &#8220;\u5b9f\u884c\u6642\u9593: &#8221; &#038; Timer &#8211; startTime &#038; &#8221; \u79d2&#8221;<br \/>\n&#8220;`<\/p>\n<p>\u4ee5\u4e0a\u306e\u70b9\u306b\u6ce8\u610f\u3057\u306a\u304c\u3089Excel \u30de\u30af\u30ed\u3092\u958b\u767a\u3059\u308b\u3053\u3068\u3067\u3001\u9ad8\u901f\u3067\u52b9\u7387\u7684\u306aVBA\u30b3\u30fc\u30c9\u3092\u4f5c\u6210\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u3053\u308c\u3089\u306e\u30c6\u30af\u30cb\u30c3\u30af\u3092\u6d3b\u7528\u3057\u3066\u3001\u696d\u52d9\u306e\u5927\u5e45\u306a\u52b9\u7387\u5316\u3092\u5b9f\u73fe\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e0a\u7d1a\u8005\u5411\u3051VBA\u30b3\u30fc\u30c9\u6700\u9069\u5316\u3068\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u30c1\u30e5\u30fc\u30cb\u30f3\u30b0\uff1a\u52b9\u7387\u7684\u306aExcel \u30de\u30af\u30ed\u306e\u6975\u610f Excel\u3092\u4f7f\u3044\u3053\u306a\u3057\u3066\u3082\u3063\u3068\u697d\u3092\u3057\u305f\u3044\u3001\u696d\u52d9\u3092\u52b9\u7387\u5316\u3057\u305f\u3044\u4e0a\u7d1a\u8005\u306e\u65b9\u306b\u3001\u3059\u3050\u306b\u8a66\u305b\u308b\u4fbf\u5229\u306a\u30de\u30af\u30ed\u30b3\u30fc\u30c9\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002\u4ee5\u4e0b\u306e\u30b3<\/p>\n","protected":false},"author":2,"featured_media":599,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[5],"tags":[],"class_list":["post-600","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-advanced"],"_links":{"self":[{"href":"https:\/\/hajidai.com\/excel\/wp-json\/wp\/v2\/posts\/600","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hajidai.com\/excel\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hajidai.com\/excel\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hajidai.com\/excel\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hajidai.com\/excel\/wp-json\/wp\/v2\/comments?post=600"}],"version-history":[{"count":0,"href":"https:\/\/hajidai.com\/excel\/wp-json\/wp\/v2\/posts\/600\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/hajidai.com\/excel\/wp-json\/wp\/v2\/media\/599"}],"wp:attachment":[{"href":"https:\/\/hajidai.com\/excel\/wp-json\/wp\/v2\/media?parent=600"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hajidai.com\/excel\/wp-json\/wp\/v2\/categories?post=600"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hajidai.com\/excel\/wp-json\/wp\/v2\/tags?post=600"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}