{"id":1182,"date":"2015-04-05T13:56:31","date_gmt":"2015-04-05T04:56:31","guid":{"rendered":"http:\/\/excelwork.info\/excel\/?p=1182"},"modified":"2017-10-12T08:03:11","modified_gmt":"2017-10-11T23:03:11","slug":"collection","status":"publish","type":"post","link":"https:\/\/excelwork.info\/excel\/collection\/","title":{"rendered":"\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\uff08Collection\uff09\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u300c\u9023\u60f3\u914d\u5217\u300d"},"content":{"rendered":"<h2>\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\uff08Collection\uff09\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u4f7f\u3044\u65b9<\/h2>\n<div class=\"m30-l\">\n<br \/><\/p>\n<div class=\"kkbox\"><strong>\u3010\u66f8\u5f0f\u3011<\/strong><\/p>\n<p><strong>Dim<\/strong> <em>myCollection<\/em> <strong>As<\/strong> <strong>Collection<\/strong><\/p>\n<p><strong>Set<\/strong> <em>myCollection<\/em> = <strong>New Collection<\/strong><\/p>\n<\/div>\n<br \/>\n<p class=\"caution4\">\n\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u3092\u5229\u7528\u3059\u308b\u305f\u3081\u3001\u5909\u6570\u3092 Collection \u578b\u3067\u5ba3\u8a00\u3057\u3001New \u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u3092\u4f7f\u7528\u3057\u3066\u3001Collection \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u30bb\u30c3\u30c8\u3057\u307e\u3059\u3002<\/p>\n<p class=\"caution4\">\n\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\uff08Collection\uff09\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f\u3001\u8981\u7d20\uff08<em>myItem<\/em>\uff09\u3068\u305d\u308c\u3092\u53d6\u308a\u51fa\u3059\u305f\u3081\u306e\u30ad\u30fc\uff08<em>Key<\/em>\uff09\u3092\u6301\u3061\u3001\u7c21\u5358\u306a<span class=\"red\"><strong>\u9023\u60f3\u914d\u5217<\/strong><\/span>\u3068\u3057\u3066\u4f7f\u7528\u3067\u304d\u307e\u3059\u3002\uff08\u672c\u683c\u7684\u306a\u9023\u60f3\u914d\u5217\u3092\u5229\u7528\u3059\u308b\u306b\u306f <a href=\"https:\/\/excelwork.info\/excel\/vbadictionary\/\">\u9023\u60f3\u914d\u5217\uff08Dictionary \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\uff09<\/a>\u3092\u53c2\u7167\u3057\u3066\u4e0b\u3055\u3044\u3002\uff09<\/p>\n<br \/>\n<div class=\"kkbox\"><strong>\u3010\u30e1\u30bd\u30c3\u30c9\u3011<\/strong><\/p>\n<p><em>myCollection<\/em>.<strong>Add<\/strong> ( <em>myItem<\/em> [, <em>Key<\/em>, <em>Before<\/em>, <em>After<\/em> ] )<\/p>\n<p><em>myCollection<\/em>.<strong>Remove<\/strong> ( { <em>Index<\/em> | <em>Key<\/em> } )<\/p>\n<p><em>myItem<\/em> = <em>myCollection<\/em>.[ <strong>Item<\/strong> ] ( { <em>Index<\/em> | <em>Key<\/em> } )\n<\/div>\n<br \/>\n<div class=\"kkbox\"><strong>\u3010\u30d7\u30ed\u30d1\u30c6\u30a3\u3011<\/strong><\/p>\n<p><em>ItemCount<\/em> = <em>myCollection<\/em>.<strong>Count<\/strong><\/p>\n<\/div>\n<br \/>\n<h3>\u3010\u5404\u9805\u76ee\u306e\u8aac\u660e\u3011<\/h3>\n<ul style=\"margin-top:0;margin-bottom:0;padding-top:0;padding-bottom:0;\">\n<li>myCollection&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\uff08 Collection \uff09\u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/li>\n<li>myItem&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\uff08 Collection \uff09\u306b\u8ffd\u52a0\u3059\u308b\u30e1\u30f3\u30d0\uff08\u8981\u7d20\uff09<\/li>\n<li>Before&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;<strong>Add \u30e1\u30bd\u30c3\u30c9<\/strong> \u4f7f\u7528\u6642\u3001<span class=\"red\">\u3053\u3053\u3067\u6307\u5b9a\u3057\u305f\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u756a\u53f7\u306e\u30e1\u30f3\u30d0\uff08\u8981\u7d20\uff09\u306e\u524d<\/span>\u306b\u8ffd\u52a0\u3057\u307e\u3059\u3002\uff08\u7701\u7565\u53ef\uff09<\/li>\n<li>After&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;<strong>Add \u30e1\u30bd\u30c3\u30c9<\/strong> \u4f7f\u7528\u6642\u3001<span class=\"red\">\u3053\u3053\u3067\u6307\u5b9a\u3057\u305f\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u756a\u53f7\u306e\u30e1\u30f3\u30d0\uff08\u8981\u7d20\uff09\u306e\u5f8c<\/span>\u306b\u8ffd\u52a0\u3057\u307e\u3059\u3002\uff08\u7701\u7565\u53ef\uff09<\/li>\n<li>Index&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\uff08 Collection \uff09\u306e\u30e1\u30f3\u30d0\uff08\u8981\u7d20\uff09\u306e\u4f4d\u7f6e\uff08\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u756a\u53f7\uff09<\/li>\n<li>Key&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\uff08 Collection \uff09\u306e\u30e1\u30f3\u30d0\uff08\u8981\u7d20\uff09\u3092\u53d6\u308a\u51fa\u3059\u3068\u304d\u306b\u4f7f\u7528\u3059\u308b\u540d\u524d\u3067\u6587\u5b57\u5217\u3067\u6307\u5b9a\u3057\u307e\u3059\u3002<strong>Add \u30e1\u30bd\u30c3\u30c9<\/strong> \u4f7f\u7528\u6642\u3001\u7701\u7565\u3057\u305f\u5834\u5408\u306f\u3001<strong>Item \u30e1\u30bd\u30c3\u30c9<\/strong> \u3067\u53d6\u308a\u51fa\u3059\u3068\u304d\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u756a\u53f7\uff08 <em>Index<\/em> \uff09\u3057\u304b\u4f7f\u7528\u3067\u304d\u307e\u305b\u3093\u3002\u307e\u305f\u3001\u6570\u5024\u3092\u6307\u5b9a\u3059\u308b\u3068\u30a8\u30e9\u30fc\u306b\u306a\u308a\u307e\u3059\uff08CStr \u7b49\u306e\u578b\u5909\u63db\u95a2\u6570\u3067\u3001\u6587\u5b57\u5217\u578b\u306b\u3059\u308b\u3068\u8a2d\u5b9a\u3067\u3044\u307e\u3059\uff09\u3002 <\/li>\n<li>ItemCount&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\uff08 Collection \uff09\u306e\u30e1\u30f3\u30d0\uff08\u8981\u7d20\uff09\u6570<\/li>\n<\/ul>\n<br \/>\n<p class=\"caution4\">\n<span class=\"red\"><strong>Item \u30e1\u30bd\u30c3\u30c9<\/strong><\/span>\u306f\u3001\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\uff08 Collection \uff09\u306e\u898f\u5b9a\u30e1\u30bd\u30c3\u30c9\u306a\u306e\u3067\u3001\u300c<strong>Item<\/strong>\u300d\u306f\u7701\u7565\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p class=\"caution4\">\n<span class=\"red\"><strong>Add \u30e1\u30bd\u30c3\u30c9<\/strong><\/span> \u3092\u5229\u7528\u3057\u3066\u8ffd\u52a0\u3057\u305f\u30e1\u30f3\u30d0\uff08\u8981\u7d20\uff09\u306b\u306f\u3001\u81ea\u52d5\u7684\u306b\uff11\u304b\u3089\u59cb\u307e\u308b\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u756a\u53f7\u304c\u3064\u3051\u3089\u308c\u307e\u3059\u3002<\/p>\n<p class=\"caution4\">\n<span class=\"red\"><strong>Add \u30e1\u30bd\u30c3\u30c9<\/strong><\/span> \u3067\u3001\u30e1\u30f3\u30d0\uff08\u8981\u7d20\uff09\u3092\u8ffd\u52a0\u3059\u308b\u969b\u3001\u3059\u3067\u306b\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u308b\u300c\u30ad\u30fc\u300d\uff08<em>Key<\/em> \uff09\u3092\u8a2d\u5b9a\u3057\u3066\u3057\u307e\u3046\u3068\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3059\u3002<\/p>\n<\/div>\n<br \/><br \/>\n<h2>\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\uff08Collection\uff09\u4f7f\u7528\u4f8b<\/h2>\n<div class=\"m30-l\">\n<h3 id=\"vba_sample\">\u30b5\u30f3\u30d7\u30ebVBA\u30bd\u30fc\u30b9<\/h3>\n<pre class=\"lang:vb mark:0 decode:true \" title=\"\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\uff08Collection\uff09\u4f7f\u7528\u4f8b\" data-url=\"http:\/\/example.co.jp\" >\r\n\u3000\r\nSub Sample_Collection_01()\r\n\r\n    Dim v, i As Long, str As String\r\n    Dim myAddress As Collection\r\n    \r\n    Set myAddress = New Collection\r\n    \r\n    myAddress.Add 25, \"Age\"                         '\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u756a\u53f7\u306f 1\r\n    \r\n    myAddress.Add \"Yamada\", \"Name\", 1               '\u300cAge\u300d\u306e\u524d\u306b\u8ffd\u52a0\u3059\u308b\u306e\u3067\u3001\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u756a\u53f7\u306f 1 \u306b\u306a\u308b\r\n    \r\n    myAddress.Add \"000-1111-2222\", \"Number\", , 1    '\u300cName\u300d\u306e\u5f8c\u306b\u8ffd\u52a0\u3059\u308b\u306e\u3067\u3001\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u756a\u53f7\u306f 2 \u306b\u306a\u308b\r\n    \r\n    For Each v In myAddress\r\n        \r\n        i = i + 1\r\n        str = str & i & \"\uff1a\" & v & Chr(13)\r\n        \r\n    Next v\r\n\r\n    MsgBox str\r\n\r\n    '\u300cItem\u300d\u306f\u7701\u7565\u53ef \uff0f \u5f15\u6570\u306f\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u756a\u53f7\u3001\u30ad\u30fc \u306e\u3069\u3061\u3089\u3067\u3082\u6307\u5b9a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\r\n    MsgBox myAddress.Item(\"Name\") & Chr(13) & _\r\n           myAddress.Item(2) & Chr(13) & _\r\n           myAddress(\"number\") & Chr(13) & _\r\n           myAddress(1)\r\n    \r\n    For i = 1 To myAddress.Count\r\n        \r\n        myAddress.Remove 1\r\n    \r\n    Next i\r\n    \r\n\r\nEnd Sub\r\n\u3000\r\n<\/pre>\n<br \/>\n<h3>\u5b9f\u884c\u7d50\u679c<\/h3>\n<p><a href=\"https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2015\/04\/collection01a.jpg?ssl=1\" rel=\"lightbox[1182]\"><img loading=\"lazy\" src=\"https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2015\/04\/collection01a.jpg?resize=172%2C214&#038;ssl=1\" alt=\"Collection 01a\" width=\"172\" height=\"214\" class=\"alignnone size-full wp-image-1193\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p><a href=\"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2015\/04\/collection01b.jpg?ssl=1\" rel=\"lightbox[1182]\"><img loading=\"lazy\" src=\"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2015\/04\/collection01b.jpg?resize=154%2C232&#038;ssl=1\" alt=\"Collection 01b\" width=\"154\" height=\"232\" class=\"alignnone size-full wp-image-1194\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<br \/>\n<h3 id=\"vba_sample\">\u30b5\u30f3\u30d7\u30ebVBA\u30bd\u30fc\u30b9<\/h3>\n<pre class=\"lang:vb mark:0 decode:true \" title=\"\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\uff08Collection\uff09\u4f7f\u7528\u4f8b\uff08\u91cd\u8907\u30c7\u30fc\u30bf\u3092\u524a\u9664\uff09\" data-url=\"http:\/\/example.co.jp\" >\r\n\u3000\r\nSub Sample_Collection_02()\r\n\r\n    Dim myItem As Collection\r\n    Dim i As Long, myStr As String\r\n    \r\n        \r\n    Set myItem = New Collection\r\n    \r\n    With Application.Worksheets(\"Sheet1\")\r\n        \r\n        '\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3059\u308b\u3068\u6b21\u306e\u51e6\u7406\u3078\u3059\u3059\u3080\r\n        On Error Resume Next\r\n        \r\n        '\u3059\u3067\u306b\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u308b\u300c\u30ad\u30fc\u300d\u3092\u8ffd\u52a0\u3057\u3088\u3046\u3068\u3059\u308b\u3068\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3059\u308b\r\n        For i = 2 To .Cells(Rows.Count, 1).End(xlUp).Row\r\n            \r\n            myItem.Add .Cells(i, 2), .Cells(i, 2)\r\n        \r\n        Next i\r\n        \r\n        On Error GoTo 0\r\n\r\n    End With\r\n    \r\n    For i = 1 To myItem.Count\r\n    \r\n        myStr = myStr & myItem.Item(i) & Chr(13)\r\n    \r\n    Next i\r\n    \r\n    MsgBox myStr\r\n    \r\nEnd Sub\r\n\u3000\r\n<\/pre>\n<br \/>\n<h3>\u5b9f\u884c\u7d50\u679c<\/h3>\n<p><a href=\"https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2015\/04\/collection02.jpg?ssl=1\" rel=\"lightbox[1182]\"><img loading=\"lazy\" src=\"https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2015\/04\/collection02.jpg?resize=400%2C276&#038;ssl=1\" alt=\"Collection 02\" width=\"400\" height=\"276\" class=\"alignnone size-medium wp-image-1195\" srcset=\"https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2015\/04\/collection02.jpg?resize=400%2C276&amp;ssl=1 400w, https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2015\/04\/collection02.jpg?resize=580%2C400&amp;ssl=1 580w, https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2015\/04\/collection02.jpg?w=585&amp;ssl=1 585w\" sizes=\"(max-width: 400px) 100vw, 400px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<br \/><\/div>\n<br \/><br \/>\n","protected":false},"excerpt":{"rendered":"<p>\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\uff08Collection\uff09\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u4f7f\u3044\u65b9 \u3010\u66f8\u5f0f\u3011 Dim my &#8230; <\/p>\n","protected":false},"author":1,"featured_media":1193,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"amp_status":"","spay_email":"","jetpack_publicize_message":"\u30d6\u30ed\u30b0\u3092\u66f4\u65b0\u3057\u307e\u3057\u305f\uff01"},"categories":[37],"tags":[63,38,80,81],"jetpack_featured_media_url":"https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2015\/04\/collection01a.jpg?fit=172%2C214&ssl=1","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p4Ye9i-j4","_links":{"self":[{"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts\/1182"}],"collection":[{"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/comments?post=1182"}],"version-history":[{"count":15,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts\/1182\/revisions"}],"predecessor-version":[{"id":6475,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts\/1182\/revisions\/6475"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/media\/1193"}],"wp:attachment":[{"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/media?parent=1182"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/categories?post=1182"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/tags?post=1182"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}