{"id":321,"date":"2018-09-19T17:56:16","date_gmt":"2018-09-19T08:56:16","guid":{"rendered":"https:\/\/blog.wewidi.com\/?p=321"},"modified":"2018-09-20T12:28:03","modified_gmt":"2018-09-20T03:28:03","slug":"%e3%80%90excelvba%e3%80%91colorindex%e3%81%ae%e4%b8%80%e8%a6%a7%e3%82%92%e4%bd%9c%e6%88%90%e3%81%99%e3%82%8b%e3%83%9e%e3%82%af%e3%83%ad%e3%82%b5%e3%83%b3%e3%83%97%e3%83%ab","status":"publish","type":"post","link":"https:\/\/blog.wewidi.com\/?p=321","title":{"rendered":"\u3010ExcelVBA\u3011ColorIndex\u306e\u4e00\u89a7\u3092\u4f5c\u6210\u3059\u308b\u30de\u30af\u30ed\u30b5\u30f3\u30d7\u30eb"},"content":{"rendered":"<p>ExcelVBA\u3067\u80cc\u666f\u8272\u3084\u6587\u5b57\u8272\u3092ColorIndex\u3067\u6307\u5b9a\u3059\u308b\u5834\u5408\u306b\u3001\u4f55\u756a\u304c\u4f55\u8272\u306a\u306e\u304b\u5224\u3089\u306a\u304b\u3063\u305f\u306e\u3067\u3001ColorIndex\u306e\u4e00\u89a7\u3092\u4f5c\u6210\u3059\u308b\u30de\u30af\u30ed\u3092\u4f5c\u6210\u3057\u3066\u307f\u305f\u3002<\/p>\n<p>\u30b7\u30fc\u30c8\u540d\u306f\u30c7\u30d5\u30a9\u30eb\u30c8\u540d\u306b\u306a\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u9069\u5f53\u306a\u540d\u524d\u306b\u4fee\u6b63\u3057\u3066\u6b32\u3057\u3044\u3002<\/p>\n<pre>\r\nSub CreateColorIndexList()\r\n    Dim mRow, nRow, nIndex, mIndex As Integer\r\n    Dim mColor, nColor, nR, nG, nB As Long  ' RGB\u5024\r\n    \r\n    mColor = &HFF               \u2019 \u8272\u306e\u6700\u5927\u5024(255)\r\n    mIndex = 56                 ' ColorIndex\u306e\u6700\u5927\u306f56\u3060\u3063\u3066\r\n    nRow = 2                    ' \u30c7\u30fc\u30bf\u90e8\u5206\u306e\u6700\u521d\u306e\u884c\r\n    \r\n    With Sheets(\"Sheet2\")       ' \u30b7\u30fc\u30c8\u540d\u306f\u9069\u5f53\u306a\u540d\u524d\u306b\u4fee\u6b63\u3059\u308b\u3053\u3068\r\n        ' \u30d8\u30c3\u30c0\u4f5c\u6210\r\n        .Cells(1, 1).Value = \"No.\"\r\n        .Cells(1, 2).Value = \"Color\"\r\n        .Cells(1, 3).Value = \"RGB\u5024\"\r\n        .Cells(1, 4).Value = \"RGB()\"\r\n\r\n        ' \u30ea\u30b9\u30c8\u4f5c\u6210\r\n        For nIndex = 1 To mIndex\r\n            .Cells(nRow, 1).Value = nIndex                  ' Index No.\r\n            .Cells(nRow, 2).Interior.ColorIndex = nIndex    ' \u80cc\u666f\u8272\u3092\u8a2d\u5b9a\r\n            nColor = .Cells(nRow, 2).Interior.Color         ' \u80cc\u666f\u8272\u306eRGB\u5024\u3092\u53d6\u5f97\r\n            .Cells(nRow, 3).Value = nColor                  ' RGB\u5024(Long)\u3092\u8a2d\u5b9a\r\n            nR = nColor And mColor                          ' Long\u5024\u3092RGB\u306b\u5206\u89e3\uff08Bit\u6f14\u7b97\uff09\r\n            nG = (nColor \\ (2 ^ 8)) And mColor\r\n            nB = nColor \\ (2 ^ 16)\r\n            .Cells(nRow, 4) = Str(nR) & \", \" & Str(nG) & \", \" & Str(nB)    ' RGB\u3092\u8a2d\u5b9a\r\n            .Cells(nRow, 2) = ZHex(nR) & \", \" & ZHex(nG) & \", \" & ZHex(nB) ' 16\u9032\u6570\u3092\u8a2d\u5b9a\r\n            nRow = nRow + 1                                 ' \u6b21\u306e\u884c\r\n        Next nIndex\r\n    End With\r\nEnd Sub\r\n\r\n\u2019 16\u9032\u6570\u6587\u5b57\u306b\u5909\u63db\uff08\u4e00\u6841\u306b\u306a\u308b\u5834\u5408\u306f\u3001\u5148\u982d\u306b\"0\"\u3092\u8ffd\u52a0\uff09\r\nFunction ZHex(ByVal nColor As Long) As String\r\n    ZHex = Right(\"0\" & Hex(nColor), 2)\r\nEnd Function\r\n<\/pre>\n<p>\u203b2018\/09\/20 Color\u5217\u306bColorCode\uff0816\u9032\u6570\uff09\u306e\u51fa\u529b\u3092\u8ffd\u52a0<\/p>\n<p>\u3053\u3093\u306a\u611f\u3058\u3002<\/p>\n<p>\u9014\u4e2d\u3067\u3001RGB\u306eLong\u5024\u3092\u3001R,G,B\u305d\u308c\u305e\u308c\u306e\u5024\u306b\u5206\u5272\u3057\u3066\u3044\u308b\u3068\u3053\u308d\u306f\u3001Bit\u6f14\u7b97\u3067\u51e6\u7406\u3057\u3066\u3044\u308b\u3002<\/p>\n<p>RGB\u306eLong\u5024\u306e\u69cb\u6210\u306f\u300116\u9032\u6570\u8868\u73fe\u3060\u3068\u300c33 CC FF\u300d\u306e\u3088\u3046\u306b6\u6841\u3067\u69cb\u6210\u3055\u308c\u3066\u3044\u3066\u3001\u5de6\u304b\u30892\u6841\u305a\u3064\u9806\u756a\u306b\u300cB\u300d\u300cG\u300d\u300cR\u300d\u306e\u5024\u3068\u306a\u3063\u3066\u3044\u308b\u3002\uff08RGB\u3067\u6307\u5b9a\u3059\u308b\u306e\u3068\u306f\u9006\u9806\u3067\u3042\u308b\u3053\u3068\u306b\u6ce8\u610f\uff09<\/p>\n<p>\u305d\u3053\u3067\u3001Bit\u6f14\u7b97\u3092\u5229\u7528\u3057\u3066\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u3053\u3068\u3092\u3084\u3063\u3066\u3044\u308b\u3002<\/p>\n<table border=\"1\">\n<tr>\n<td>RGB<\/td>\n<td>Code<\/td>\n<td>\u51e6\u7406\u5185\u5bb9\uff08\u6841\u304c\u5224\u308b\u3088\u304616\u9032\u6570\u5024\u300c33CCFF\u300d\u3092\u4f8b\u306b\u3059\u308b\uff09<\/td>\n<\/tr>\n<tr>\n<td>R<\/td>\n<td>nR = nColor And &#038;HFF<\/td>\n<td>RGB\u5024\u306b[00][00][FF]\u3092And\u3059\u308b\u3053\u3068\u3067\u3001\u6700\u5f8c\u306e[FF]\u3060\u3051\u3092\u53d6\u308a\u51fa\u3059<\/td>\n<\/tr>\n<tr>\n<td>G<\/td>\n<td>nG = (nColor \\ (2 ^ 8)) And &#038;HFF<\/td>\n<td>1) RGB\u5024\u30928 Bit\u5206\u53f3\u306b\u30b7\u30d5\u30c8(\u300c\\(2^8)\u300d\u306e\u90e8\u5206)\u3057\u3066\u3001\u6700\u5f8c\u306e[FF]\u3092\u524a\u9664<br \/>2) RGB\u5024\u306f[33][CC]\u3068\u306a\u308b<br \/>3) RGB\u5024[33][CC]\u306b[00][FF]\u3092AND\u3057\u3066\u3001[CC]\u306e\u307f\u3092\u53d6\u308a\u51fa\u3059<\/td>\n<\/tr>\n<tr>\n<td>B<\/td>\n<td>nB = nColor \\ (2 ^ 16)<\/td>\n<td>RGB\u5024\u309216 Bit\u5206\u53f3\u306b\u30b7\u30d5\u30c8(\u300c\\2^16\u300d\u306e\u90e8\u5206)\u3059\u308b\u3053\u3068\u3067\u3001[33]\u306e\u307f\u3092\u53d6\u308a\u51fa\u3059<\/td>\n<\/tr>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>ExcelVBA\u3067\u80cc\u666f\u8272\u3084\u6587\u5b57&#8230;<\/p>\n","protected":false},"author":1,"featured_media":184,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[6,40,46,4],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/blog.wewidi.com\/index.php?rest_route=\/wp\/v2\/posts\/321"}],"collection":[{"href":"https:\/\/blog.wewidi.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.wewidi.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.wewidi.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.wewidi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=321"}],"version-history":[{"count":13,"href":"https:\/\/blog.wewidi.com\/index.php?rest_route=\/wp\/v2\/posts\/321\/revisions"}],"predecessor-version":[{"id":338,"href":"https:\/\/blog.wewidi.com\/index.php?rest_route=\/wp\/v2\/posts\/321\/revisions\/338"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.wewidi.com\/index.php?rest_route=\/wp\/v2\/media\/184"}],"wp:attachment":[{"href":"https:\/\/blog.wewidi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=321"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.wewidi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=321"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.wewidi.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=321"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}