{"id":3488,"date":"2022-07-30T12:00:02","date_gmt":"2022-07-30T03:00:02","guid":{"rendered":"https:\/\/www.bold.ne.jp\/engineer-club\/?p=3488"},"modified":"2025-11-19T10:34:51","modified_gmt":"2025-11-19T01:34:51","slug":"vba-function","status":"publish","type":"post","link":"https:\/\/www.bold.ne.jp\/engineer-club\/vba-function","title":{"rendered":"VBA\u306eFunction\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u3068\u306f\uff1fFunction\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u306e\u69cb\u6587\u3084\u4f7f\u3044\u65b9"},"content":{"rendered":"<p>VBA\u306e\u4f5c\u6210\u6642\u306b\u3001\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u306e\u7d50\u679c\u3092\u547c\u51fa\u3057\u5143\u3067\u4f7f\u7528\u3057\u305f\u3044\u5834\u5408\u3001<span>Function<\/span>\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u5185\u3067\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u540d\u306b\u5024\u3092\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u3067\u5024\u3092\u8fd4\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u3053\u3053\u3067\u306f\u3001\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9\u306b\u3064\u3044\u3066\u8aac\u660e\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<div id=\"toc_container\" class=\"no_bullets\"><p class=\"toc_title\">\u76ee\u6b21<\/p><ul class=\"toc_list\"><li><a href=\"#VBAFunction\">\uff11\uff0eVBA\u306eFunction\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u306b\u3064\u3044\u3066<\/a><ul><li><a href=\"#-Function\">\uff11-\uff11\uff0eFunction\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u3068\u306f<\/a><\/li><li><a href=\"#-Function-2\">\uff11-\uff12\uff0eFunction\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u306e\u69cb\u6587<\/a><\/li><\/ul><\/li><li><a href=\"#Sub\">\uff12\uff0eSub\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u3068\u306e\u9055\u3044\u306b\u3064\u3044\u3066<\/a><\/li><li><a href=\"#Function\">\uff13\uff0eFunction\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u306e\u4f7f\u7528\u4f8b<\/a><ul><li><a href=\"#i\">\uff13-\uff11\uff0e\u57fa\u672c\u7684\u306a\u4f7f\u7528\u4f8b<\/a><\/li><li><a href=\"#i-2\">\uff13-\uff12\uff0e\u7279\u6b8a\u306a\u66f8\u304d\u65b9\u3092\u3059\u308b\u5834\u5408<\/a><\/li><li><a href=\"#i-3\">\uff13-\uff13\uff0e\u305d\u306e\u4ed6\u306e\u4f7f\u7528\u4f8b<\/a><\/li><\/ul><\/li><li><a href=\"#i-4\">\uff14\uff0e\u6700\u5f8c\u306b<\/a><\/li><\/ul><\/div>\n<h2><span id=\"VBAFunction\">\uff11\uff0eVBA\u306e<span>Function<\/span>\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u306b\u3064\u3044\u3066<\/span><\/h2>\n<h3><span id=\"-Function\"><span>\uff11-\uff11\uff0eFunction<\/span>\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u3068\u306f<\/span><\/h3>\n<p><span>Function<\/span>\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u3068\u306f\u3001<strong>VBA\u5185\u3067\u7279\u5b9a\u306e\u51e6\u7406\u3092\u884c\u3044\u3001\u5024\u3092\u8fd4\u3059\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u306e\u3053\u3068<\/strong>\u3067\u3059\u3002\u5358\u4f53\u3067\u4f7f\u7528\u3059\u308b\u306e\u3067\u306f\u306a\u304f\u3001\u4ed6\u306e\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u304b\u3089\u547c\u3070\u308c\u308b\u3053\u3068\u304c\u307b\u3068\u3093\u3069\u3067\u3059\u3002<\/p>\n<h3><span id=\"-Function-2\"><span>\uff11-\uff12\uff0eFunction<\/span>\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u306e\u69cb\u6587<\/span><\/h3>\n<p><span>Function<\/span>\u306f\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306b\u8a18\u8ff0\u3057\u307e\u3059\u3002<\/p>\n<p><strong>\u300c\u30b9\u30b3\u30fc\u30d7\u300d Function \u300c\u95a2\u6570\u540d\u300d (\u5f15\u6570 as \u5f15\u6570\u306e\u578b) \u623b\u308a\u5024\u306e\u578b<\/strong><\/p>\n<h4><span>\uff11-\uff12-\uff11\uff0e<\/span>\u30b9\u30b3\u30fc\u30d7<\/h4>\n<p>\u30b9\u30b3\u30fc\u30d7\u306b\u306f\u3001\u4e0b\u8a18\u306e<span>3<\/span>\u7a2e\u985e\u304c\u3042\u308a\u307e\u3059\u3002\u7701\u7565\u53ef\u80fd\u3067\u3001\u7701\u7565\u3057\u305f\u5834\u5408\u306f\u300c<span>Public<\/span>\u300d\u304c\u8a2d\u5b9a\u3055\u308c\u305f\u72b6\u614b\u3068\u540c\u3058\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<blockquote>\n<p><strong>1\uff09Public<\/strong><\/p>\n<p>\u3059\u3079\u3066\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u304b\u3089\u53c2\u7167\u3057\u305f\u3044\u5834\u5408\u306b\u8a2d\u5b9a\u3057\u307e\u3059<\/p>\n<p><strong>2\uff09Private<\/strong><\/p>\n<p><span>Function<\/span>\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u3092\u8a18\u8ff0\u3057\u305f\u30e2\u30b8\u30e5\u30fc\u30eb\u304b\u3089\u306e\u307f\u53c2\u7167\u3057\u305f\u3044\u5834\u5408\u306b\u8a2d\u5b9a\u3057\u307e\u3059<\/p>\n<p><strong>3\uff09Friend<\/strong><\/p>\n<p>\u30af\u30e9\u30b9\u30e2\u30b8\u30e5\u30fc\u30eb\u3067\u306e\u307f\u4f7f\u7528\u3067\u304d\u307e\u3059<\/p>\n<\/blockquote>\n<h4><span>\uff11-\uff12-\uff12\uff0e<\/span>\u95a2\u6570\u540d<\/h4>\n<p>\u95a2\u6570\u306e\u540d\u524d\u3092\u8a2d\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<h4><span>\uff11-\uff12-\uff13\uff0e<\/span>\u5f15\u6570<\/h4>\n<p>\u7701\u7565\u53ef\u80fd\u3067\u3059\u3002\u547c\u3070\u308c\u305f\u3068\u304d\u306b\u6e21\u3055\u308c\u308b\u5f15\u6570\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002\u8907\u6570\u6307\u5b9a\u3059\u308b\u5834\u5408\u306f\u3001\u30b3\u30f3\u30de\u3067\u533a\u5207\u308a\u307e\u3059\u3002<\/p>\n<h4><span>\uff11-\uff12-\uff14\uff0e<\/span>\u623b\u308a\u5024\u306e\u578b<\/h4>\n<p>\u8fd4\u3055\u308c\u308b\u5024\u306e\u30c7\u30fc\u30bf\u578b\u3092\u8a2d\u5b9a\u3057\u307e\u3059\u3002<span>Function<\/span>\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u5185\u3067\u3001\u623b\u3057\u305f\u3044\u5024\u3092\u95a2\u6570\u540d\u306b\u5165\u308c\u307e\u3059\u3002\u7701\u7565\u53ef\u80fd\u3067\u3059\u3002\u7701\u7565\u3057\u305f\u5834\u5408\u3001\u547c\u3073\u51fa\u3057\u5143\u3067\u623b\u308a\u5024\u3092\u8a2d\u5b9a\u3059\u308b\u5909\u6570\u306e\u578b\u306b\u300c\u6697\u9ed9\u306e\u578b\u5909\u63db\u300d\u3092\u884c\u3044\u307e\u3059\u3002\u5909\u63db\u3067\u304d\u306a\u3044\u5834\u5408\u306f\u3001\u30a8\u30e9\u30fc\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2><span id=\"Sub\"><span>\uff12\uff0eSub<\/span>\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u3068\u306e\u9055\u3044\u306b\u3064\u3044\u3066<\/span><\/h2>\n<p>\u5909\u6570\u3092\u5ba3\u8a00\u3059\u308b\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u3068\u3057\u3066\u3001<span>Sub<\/span>\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u304c\u3042\u308a\u307e\u3059\u3002<span>Sub<\/span>\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u3068\u306e\u9055\u3044\u306f\u3001\u5024\u3092\u623b\u3059\u304b\u3069\u3046\u304b\u3067\u3059\u3002<\/p>\n<h2><span id=\"Function\"><span>\uff13\uff0eFunction<\/span>\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u306e\u4f7f\u7528\u4f8b<\/span><\/h2>\n<h3><span id=\"i\">\uff13-\uff11\uff0e\u57fa\u672c\u7684\u306a\u4f7f\u7528\u4f8b<\/span><\/h3>\n<p>\u5f15\u6570\u3067\u5024\u3092\u6e21\u3057\u3066\u3001\u623b\u3057\u305f\u5024\u3092\u30e1\u30c3\u30bb\u30fc\u30b8\u306b\u8868\u793a\u3059\u308b\u51e6\u7406\u7b49\u3067\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">Sub main()\r\n    Dim ret As Long\r\n\r\n    ret = sample01(100)\r\n    MsgBox \"\u5024\u306f\" &amp; ret\r\n\r\nEnd Sub\r\n\r\n'\u5f15\u6570val\u306e\u5024\u30922\u500d\u306b\u3057\u3066\u623b\u3057\u307e\u3059\r\nFunction sample01(val As Long) As Long\r\n\r\n\u3000\u3000'\u623b\u308a\u5024\u3092\u8a2d\u5b9a\r\n    sample01 = val * 2\r\n\r\nEnd Function<\/pre>\n<p><strong>\u5b9f\u884c\u7d50\u679c\uff1a<\/strong><\/p>\n<p><a href=\"https:\/\/www.bold.ne.jp\/engineer-club\/wp-content\/uploads\/2022\/07\/\u30ba.png\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/www.bold.ne.jp\/engineer-club\/wp-content\/uploads\/2022\/07\/\u30ba.png\" alt=\"\" width=\"160\" height=\"186\" class=\"alignnone size-full wp-image-3490\" \/><\/a><\/p>\n<h3><span id=\"i-2\">\uff13-\uff12\uff0e\u7279\u6b8a\u306a\u66f8\u304d\u65b9\u3092\u3059\u308b\u5834\u5408<\/span><\/h3>\n<p><span>Function<\/span>\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u306e\u6697\u9ed9\u306e\u578b\u5909\u63db\u3002<span>sample02<\/span>\u306f\u623b\u308a\u5024\u306e\u578b\u3092\u6307\u5b9a\u3057\u3066\u3044\u306a\u3044\u306e\u3067\u3001\u6570\u5b57\u3068\u3057\u3066\u306e\u300c<span>200<\/span>\u300d\u3092\u623b\u3057\u3066\u3044\u307e\u3059\u3002<span>samplw03<\/span>\u306f\u623b\u308a\u5024\u306e\u578b\u3092\u6307\u5b9a\u3057\u3066\u3044\u306a\u3044\u306e\u3067\u3001\u306f\u6587\u5b57\u5217\u3068\u3057\u3066\u306e\u300c<span>200<\/span>\u300d\u3092\u623b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">Sub main()\r\n    Dim ret As String\r\n\r\n    ret = sample02\r\n    MsgBox \"sample02\u306e\u623b\u308a\u5024\u306f\" &amp; ret\r\n\r\n    ret = sample03\r\n    MsgBox \"sample03\u306e\u623b\u308a\u5024\u306f\" &amp; ret\r\nEnd Sub\r\n\r\n\r\n'\u6570\u5b57\u306e200\u3092\u8fd4\u3057\u307e\u3059\r\nFunction sample02() '\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u306e\u623b\u308a\u5024\u5b9a\u7fa9\u306a\u3057\r\n\r\n    sample02 = 200\r\n\r\nEnd Function\r\n\r\n'\u6587\u5b57\u5217\u306e200\u3092\u8fd4\u3057\u307e\u3059\r\nFunction sample03() '\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u306e\u623b\u308a\u5024\u5b9a\u7fa9\u306a\u3057\r\n\r\n    sample03 = \"200\"\r\n\r\nEnd Function<\/pre>\n<p><strong>\u5b9f\u884c\u7d50\u679c\uff1a<\/strong><\/p>\n<p><a href=\"https:\/\/www.bold.ne.jp\/engineer-club\/wp-content\/uploads\/2022\/07\/\u56f32-1.png\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/www.bold.ne.jp\/engineer-club\/wp-content\/uploads\/2022\/07\/\u56f32-1.png\" alt=\"\" width=\"202\" height=\"186\" class=\"alignnone size-full wp-image-3491\" \/><\/a><a href=\"https:\/\/www.bold.ne.jp\/engineer-club\/wp-content\/uploads\/2022\/07\/\u56f33-1.png\">\u3000\u3000\u3000<img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/www.bold.ne.jp\/engineer-club\/wp-content\/uploads\/2022\/07\/\u56f33-1.png\" alt=\"\" width=\"202\" height=\"186\" class=\"alignnone size-full wp-image-3492\" \/><\/a><\/p>\n<h3><span id=\"i-3\">\uff13-\uff13\uff0e\u305d\u306e\u4ed6\u306e\u4f7f\u7528\u4f8b<\/span><\/h3>\n<h4>\uff13-\uff13-\uff11\uff0e\u51e6\u7406\u306e\u9014\u4e2d\u3067\u629c\u3051\u308b<\/h4>\n<p>\u51e6\u7406\u306e\u9014\u4e2d\u3067<span>Function<\/span>\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u3092\u7d42\u4e86\u3055\u305b\u305f\u3044\u5834\u5408\u306f\u3001\u7d42\u4e86\u3055\u305b\u305f\u3044\u5834\u6240\u306b\u300c<span>exit Function<\/span>\u300d\u3092\u5165\u308c\u307e\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">Sub main()\r\n    Dim ret As String\r\n\r\n    ret = sample04(200)\r\n    MsgBox \"\u623b\u308a\u5024\u306f\" &amp; ret\r\n\r\nEnd Sub\r\n\r\nFunction sample04(val As Long)\r\n\r\n    If val &gt; 100 Then\r\n        sample04 = val\r\n        Exit Function\r\n    End If\r\n    \r\n    MsgBox \"\u5f15\u6570\u306f100\u8d85\"\r\n    val = val - 50\r\n    sample04 = val\r\n    Exit Function\r\n    \r\nEnd Function<\/pre>\n<p><strong>\u5b9f\u884c\u7d50\u679c\uff1a<\/strong><\/p>\n<p><a href=\"https:\/\/www.bold.ne.jp\/engineer-club\/wp-content\/uploads\/2022\/07\/\u56f34-1.png\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/www.bold.ne.jp\/engineer-club\/wp-content\/uploads\/2022\/07\/\u56f34-1.png\" alt=\"\" width=\"160\" height=\"186\" class=\"alignnone size-full wp-image-3493\" \/><\/a><\/p>\n<h4>\uff13-\uff13-\uff12\uff0e\u51e6\u7406\u306e\u7d50\u679c\u3092\u8907\u6570\u623b\u3057\u305f\u3044\u5834\u5408<\/h4>\n<p>\u623b\u308a\u5024\u3092\u8907\u6570\u623b\u3057\u305f\u3044\u5834\u5408\u306f\u3001\u5f15\u6570\u3067\u300c<span>ByRef<\/span>\u300d\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">Sub main()\r\n    Dim ret1 As String\r\n    Dim ret2 As String\r\n\r\n    ret1 = sample05(\"\u79c1\", 30, \"\u4f1a\u793e\u54e1\", ret2)\r\n    MsgBox ret1 &amp; vbCrLf &amp; ret2\r\n\r\nEnd Sub\r\n\r\nFunction sample05(str1 As String, val As Long, str2 As String, ByRef ret As String) As String\r\n\r\n    sample05 = str1 &amp; \"\u306e\u5e74\u9f62\u306f\" &amp; val &amp; \"\u6b73\u3067\u3059\"\r\n    ret = str1 &amp; \"\u306e\u8077\u696d\u306f\" &amp; str2 &amp; \"\u3067\u3059\"\r\n    \r\nEnd Function<\/pre>\n<p><strong>\u5b9f\u884c\u7d50\u679c\uff1a<\/strong><\/p>\n<p><a href=\"https:\/\/www.bold.ne.jp\/engineer-club\/wp-content\/uploads\/2022\/07\/\u56f35-1.png\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/www.bold.ne.jp\/engineer-club\/wp-content\/uploads\/2022\/07\/\u56f35-1.png\" alt=\"\" width=\"188\" height=\"205\" class=\"alignnone size-full wp-image-3494\" \/><\/a><\/p>\n<h2><span id=\"i-4\">\uff14\uff0e\u6700\u5f8c\u306b<\/span><\/h2>\n<p><span>Function<\/span>\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u306f\u3001<span>Java<\/span>\u7b49\u306e\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u306e\u3088\u3046\u306b\u3001\u5f15\u6570\u3092\u8fd4\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<span>Sub<\/span>\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u3068\u4f7f\u3044\u5206\u3051\u3066<span>VBA<\/span>\u3092\u4f5c\u6210\u3057\u3066\u3044\u3063\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>VBA\u306e\u4f5c\u6210\u6642\u306b\u3001\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u306e\u7d50\u679c\u3092\u547c\u51fa\u3057\u5143\u3067\u4f7f\u7528\u3057\u305f\u3044\u5834\u5408\u3001Function\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u5185\u3067\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u540d\u306b\u5024\u3092\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u3067\u5024\u3092\u8fd4\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u3053\u3053\u3067\u306f\u3001\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9\u306b\u3064\u3044\u3066\u8aac\u660e\u3057\u3066\u3044\u304d\u307e\u3059\u3002 \u76ee\u6b21\uff11\uff0eVBA [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":3495,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"acf":[],"_links":{"self":[{"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/posts\/3488"}],"collection":[{"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/comments?post=3488"}],"version-history":[{"count":5,"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/posts\/3488\/revisions"}],"predecessor-version":[{"id":6098,"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/posts\/3488\/revisions\/6098"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/media\/3495"}],"wp:attachment":[{"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/media?parent=3488"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/categories?post=3488"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}