{"id":2082,"date":"2014-08-22T19:48:04","date_gmt":"2014-08-22T10:48:04","guid":{"rendered":"http:\/\/www23.atpages.jp\/~inoni\/?p=2082"},"modified":"2017-10-20T17:27:24","modified_gmt":"2017-10-20T08:27:24","slug":"excelvba%e8%a6%9a%e6%9b%b8-autofilter%e3%81%be%e3%81%a8%e3%82%81","status":"publish","type":"post","link":"http:\/\/anada.cloudfree.jp\/?p=2082","title":{"rendered":"ExcelVBA\u899a\u66f8 AutoFilter\u307e\u3068\u3081"},"content":{"rendered":"<p>\u3042\u3041\u3001\u30d5\u30a3\u30eb\u30bf\u3088\u3001\u30d5\u30a3\u30eb\u30bf\u3088\u30fb\u30fb\u30fb<br \/>\n\u7d50\u69cb\u3084\u3084\u3053\u3057\u304b\u3063\u305f\u305e\u3088\u3002<\/p>\n<p>1\u3064\u306e\u5217\u306b\u5bfe\u3059\u308b\u8907\u6570\u6761\u4ef6\u306e\u8a2d\u5b9a\u3068\u304b\u3001\u30d5\u30a3\u30eb\u30bf\u89e3\u9664\u306e\u65b9\u6cd5\u3084\u3089\u3001\u30de\u30af\u30ed\u306e\u8a18\u9332\u3067\u51fa\u529b\u3055\u308c\u306a\u3044\u30ed\u30b8\u30c3\u30af\u3092\u8abf\u3079\u308b\u306e\u306b\u6642\u9593\u304c\u304b\u304b\u3063\u305f\u3002<\/p>\n<p><strong>1) \u30d5\u30a3\u30eb\u30bf\u306e\u89e3\u9664<\/strong><\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\n' \u30d5\u30a3\u30eb\u30bf\u304c\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u305f\u3089\u89e3\u9664\u3057\u3061\u3083\u3046\u3088\nPrivate Sub ClearAutoFilter(target_ws as Worksheet)\n    If target_ws.AutoFilterMode Then target_ws.AutoFilterMode = False\nEnd Sub\n<\/pre>\n<p><strong>2) 1\u3064\u306e\u5217\u306b\u5bfe\u3059\u308b\u8907\u6570\u6761\u4ef6\u8a2d\u5b9a<\/strong><\/p>\n<p>\u3053\u308c\u304c\u7d50\u69cb\u96e3\u3057\u304b\u3063\u305f\u3002\u3068\u3044\u3046\u3088\u308a\u3001\u53c2\u8003\u306b\u306a\u308b\u30b5\u30a4\u30c8\u304c\u3042\u307e\u308a\u306a\u304f\u3001\u3084\u3063\u3068\u3053\u3055\u3067\u63a2\u3057\u5f53\u3066\u305f\u3002<br \/>\n\u5225\u306e\u3068\u3053\u308d\u3067\u914d\u5217(Variant\u578b)\u3092\u4f5c\u3063\u3068\u304f\u3002<br \/>\n\u305f\u3068\u3048\u3070\u3001<br \/>\n    Dim arr As Varient<br \/>\n    arr = Split(&#8220;\u3042,\u3044,\u3046&#8221;)<br \/>\n\u3068\u3057\u3066\u3001<br \/>\n    SetAutoFilterAt Activesheet.Range(&#8220;A1:E100&#8221;), 1, arr<br \/>\n\u3063\u3066\u306a\u611f\u3058\u3067\u4e0b\u306e\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u3092\u547c\u3073\u51fa\u3059\u3002<br \/>\n\u3059\u308b\u3068\u3001\u300c\u3042\u300d\u300c\u3044\u300d\u300c\u3046\u300d\u306b\u8a72\u5f53\u3059\u308b\u30ec\u30b3\u30fc\u30c9\u304c\u62bd\u51fa\u3055\u308c\u308b\u3002<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\nPrivate Sub SetAutoFilterOn(target_rng as Range, col as Long, crit_arr as Variant)\n    target_rng.AutoFilter Field:=col , Criteria1:=crit_arr , Operator:=xlFilterValues\nEnd Sub\n<\/pre>\n<p>\u8a66\u3057\u3066\u306a\u3044\u304b\u3089\u3001\u52d5\u304b\u3093\u304b\u3063\u305f\u3089\u3054\u3081\u3093\u306a\u3055\u3044\u3002<br \/>\n\u3067\u3082\u3001\u30a4\u30e1\u30fc\u30b8\u7684\u306b\u306f\u3053\u3093\u306a\u611f\u3058\u3067\u3001Criteria1\u3068Operator \u306e\u8a2d\u5b9a\u304c\u30dd\u30a4\u30f3\u30c8\u3068\u3044\u3046\u3053\u3068\u304c\u5206\u304b\u3063\u305f\u3002<\/p>\n<p><strong>3) \u7d5e\u308a\u8fbc\u3093\u3060\u30c7\u30fc\u30bf\u306e\u53d6\u5f97(A) 1\u884c\u305a\u3064\u6f01\u308b<\/strong><\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\n    Dim cnt As Long\n    Dim rng As Range\n    Dim target_rng As Range\n\n    Set target_rng = Activesheet.Range(&quot;A1:E100&quot;)\n\n    'target_rng\u306e1\u884c\u76ee\u304c\u30bf\u30a4\u30c8\u30eb\u884c\u306a\u306e\u3067\u3001-1 \u3059\u308b\u3002\n    With target_rng\n        cnt = .Columns(1).SpecialCells(xlCellTypeVisible).Cells.Count -1\n        If cnt &gt; 0 Then\n            For Each rng In .Columns(1).SpecialCells(xlCellTypeVisible).Cells\n                '\u30bf\u30a4\u30c8\u30eb\u884c\u4ee5\u5916\u3067\u51e6\u7406\u3059\u308b\n                If rng.Row &gt; 1 Then\n                    '\u62bd\u51fa\u7bc4\u56f2\u306e1\u5217\u76ee\u306e\u60c5\u5831\u3092\u30c0\u30a4\u30a2\u30ed\u30b0\u8868\u793a\n                    Msgbox rng.Parent.Cells(rng.row,1).Value\n                End If\n            Next\n        Else\n            Msgbox &quot;\u30c7\u30fc\u30bf\u306a\u3057&quot;\n        End If\n    End With\n<\/pre>\n<p>ForEach\u6587\u304c1\u884c\u305a\u3064\u898b\u3066\u3044\u308b\u3068\u3053\u308d\u3002<br \/>\n\u62bd\u51fa\u7bc4\u56f2\u306e1\u5217\u76ee\u3063\u3066\u306e\u304c\u3001Columns(1).SpecialCells(xlCellTypeVisible).Cells\u3002<\/p>\n<p><strong>4) \u7d5e\u308a\u8fbc\u3093\u3060\u30c7\u30fc\u30bf\u306e\u53d6\u5f97(B) \u30ef\u30fc\u30af\u30b7\u30fc\u30c8\u95a2\u6570\u3067\u30c9\u30d0\u30c3\u3068\u96c6\u8a08<\/strong><\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\n    Dim cnt As Long\n    Dim target_rng As Range\n    \n    Set target_rng = Activesheet.Range(&quot;A1:E100&quot;)\n\n    'target_rng\u306e1\u884c\u76ee\u304c\u30bf\u30a4\u30c8\u30eb\u884c\u306a\u306e\u3067\u3001-1 \u3059\u308b\u3002\n    With target_rng\n        cnt = .Columns(1).SpecialCells(xlCellTypeVisible).Cells.Count -1\n        If cnt &gt; 0 Then\n             '\u62bd\u51fa\u7bc4\u56f2\u306e2\u5217\u76ee\u306e\u5408\u8a08\u3092\u53d6\u5f97(\u30bf\u30a4\u30c8\u30eb\u884c\u306f\u6570\u5024\u3067\u306a\u3044\u3053\u3068)\n             Msgbox  &quot;\u5408\u8a08\uff1a&quot; &amp; Cstr(Application.WorksheetFunction.Sum(.Columns(2).SpecialCells(xlCellTypeVisible).Cells))\n        Else\n            Msgbox &quot;\u30c7\u30fc\u30bf\u306a\u3057&quot;\n        End If\n    End With\n<\/pre>\n<p>\u4ed6\u306e\u5185\u5bb9\u306f\u5272\u3068\u7c21\u5358\u306b\u8abf\u3079\u3089\u308c\u308b\u306e\u3067\u7701\u7565\u3002<\/p>\n<p>\u6539\u3081\u3066ExcelVBA\u3063\u3066\u5965\u6df1\u3044\u306a\u3041\u30fb\u30fb\u30fb\u3063\u3066\u601d\u3063\u305f\u3002<br \/>\n\u3063\u3066\u304b\u3001\u30de\u30af\u30ed\u306e\u8a18\u9332\u3067\u3053\u3046\u3044\u3046\u30ed\u30b8\u30c3\u30af\u3092\u6b8b\u3057\u3066\u304f\u308c\u305f\u3089\u3001\u60a9\u307e\u305a\u306b\u6e08\u3080\u306e\u306b\uff01\u3068\u3044\u3064\u3082\u601d\u3046\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3042\u3041\u3001\u30d5\u30a3\u30eb\u30bf\u3088\u3001\u30d5\u30a3\u30eb\u30bf\u3088\u30fb\u30fb\u30fb \u7d50\u69cb\u3084\u3084\u3053\u3057\u304b\u3063\u305f\u305e\u3088\u3002 1\u3064\u306e\u5217\u306b\u5bfe\u3059\u308b\u8907\u6570\u6761\u4ef6\u306e\u8a2d\u5b9a\u3068\u304b\u3001\u30d5\u30a3\u30eb\u30bf\u89e3\u9664\u306e\u65b9\u6cd5\u3084\u3089\u3001\u30de\u30af\u30ed\u306e\u8a18\u9332\u3067\u51fa\u529b\u3055\u308c\u306a\u3044\u30ed\u30b8\u30c3\u30af\u3092\u8abf\u3079\u308b\u306e\u306b\u6642\u9593\u304c\u304b\u304b\u3063\u305f\u3002 1) \u30d5\u30a3\u30eb\u30bf\u306e\u89e3\u9664 &#8216; \u30d5\u30a3\u30eb\u30bf [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[43,74],"class_list":["post-2082","post","type-post","status-publish","format-standard","hentry","category-excelvba","tag-excel","tag-vba"],"_links":{"self":[{"href":"http:\/\/anada.cloudfree.jp\/index.php?rest_route=\/wp\/v2\/posts\/2082","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/anada.cloudfree.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/anada.cloudfree.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/anada.cloudfree.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/anada.cloudfree.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2082"}],"version-history":[{"count":1,"href":"http:\/\/anada.cloudfree.jp\/index.php?rest_route=\/wp\/v2\/posts\/2082\/revisions"}],"predecessor-version":[{"id":2685,"href":"http:\/\/anada.cloudfree.jp\/index.php?rest_route=\/wp\/v2\/posts\/2082\/revisions\/2685"}],"wp:attachment":[{"href":"http:\/\/anada.cloudfree.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2082"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/anada.cloudfree.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2082"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/anada.cloudfree.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2082"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}