{"id":677,"date":"2023-09-28T18:49:51","date_gmt":"2023-09-28T18:49:51","guid":{"rendered":"https:\/\/exceladvisor.org\/cn\/%e5%a6%82%e6%9e%9c-2\/"},"modified":"2023-12-10T11:49:33","modified_gmt":"2023-12-10T11:49:33","slug":"%e5%a6%82%e6%9e%9c-2","status":"publish","type":"page","link":"https:\/\/exceladvisor.org\/cn\/%e5%a6%82%e6%9e%9c-2\/","title":{"rendered":"\u5982\u4f55\u5728vba\u4e2d\u4f7f\u7528if\u8bed\u53e5\u548celse\uff1f"},"content":{"rendered":"<div class=\"excel-\" id=\"excel-899293268\"><script type=\"text\/javascript\">\r\n\tatOptions = {\r\n\t\t'key' : 'c1158f160081d6540a8409e6925dab94',\r\n\t\t'format' : 'iframe',\r\n\t\t'height' : 250,\r\n\t\t'width' : 300,\r\n\t\t'params' : {}\r\n\t};\r\n<\/script>\r\n<script type=\"text\/javascript\" src=\"\/\/www.highperformanceformat.com\/c1158f160081d6540a8409e6925dab94\/invoke.js\"><\/script><\/div> <p>\u5982\u679c\u4f60\u60f3\u6210\u4e3aVBA\u9ad8\u7ea7\u7528\u6237\uff0cIF\u8bed\u53e5\u662f\u5fc5\u987b\u7684\u3002\u800c\u4e14\uff0c\u6211\u76f8\u4fe1\u60a8\u5df2\u7ecf\u77e5\u9053 IF \u8fd9\u4e2a\u8bcd\u5e76\u7ecf\u5e38\u5c06\u5176\u7528\u4f5c\u7535\u5b50\u8868\u683c\u51fd\u6570\u3002<\/p><p>\u5728 VBA \u4e2d\uff0cIF \u7684\u5de5\u4f5c\u65b9\u5f0f\u76f8\u540c\u3002\u5b83\u7684\u57fa\u672c\u601d\u60f3\u662f\u5f53\u6761\u4ef6\u4e3a\u771f\u65f6\u6267\u884c\u4efb\u52a1\uff0c\u5426\u5219\u4e0d\u6267\u884c\u4efb\u4f55\u64cd\u4f5c\u6216\u6267\u884c\u5176\u4ed6\u64cd\u4f5c\u3002\u60a8\u53ef\u4ee5\u7b80\u5355\u5730\u5199\u4f5c\uff0c\u4e5f\u53ef\u4ee5\u5728\u590d\u6742\u7684\u60c5\u51b5\u4e0b\u5199\u4f5c\u3002<\/p><p>\u4e3a\u4e86\u4fbf\u4e8e\u7406\u89e3\uff0c\u6211\u5c06\u5176\u5206\u4e3a\u4e09\u4e2a\u4e0d\u540c\u7684\u90e8\u5206\u3002<\/p><ul><li>\u63d0\u4f9b\u4ee5\u4f9b\u6d4b\u8bd5\u3002<\/li><li>\u6761\u4ef6\u4e3a TRUE \u65f6\u6267\u884c\u7684\u4efb\u52a1\u3002<\/li><li>\u6761\u4ef6\u4e3a FALSE \u65f6\u6267\u884c\u7684\u4efb\u52a1\u3002<\/li><\/ul><p>\u8fd9\u5c31\u662f\u73b0\u5b9e\u751f\u6d3b\u4e2d\u7684\u6837\u5b50\uff1a <\/p><div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/exceladvisor.org\/wp-content\/uploads\/2023\/08\/en-utilisant-le-code-dinstruction-VBA-IF-dans-Excel.png\" sizes=\"\" srcset=\"\" alt=\"\u5728Excel\u4e2d\u4f7f\u7528VBA IF\u8bed\u53e5\u4ee3\u7801\"><\/figure><\/div><p>\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u4e0b\u96e8\u662f\u4e00\u4e2a\u6761\u4ef6\u3002\u5982\u679c\u8fd9\u4e2a\u6761\u4ef6\u4e3a\u771f\uff0c\u7537\u5b69\u5c31\u4f1a\u6253\u5f00\u96e8\u4f1e\uff0c\u5982\u679c\u6761\u4ef6\u4e3a\u5047\uff0c\u4ed6\u5c31\u4f1a\u6234\u4e0a\u5e3d\u5b50\u3002\u6761\u4ef6\u5728\u6211\u4eec\u7684\u65e5\u5e38\u751f\u6d3b\u4e2d\u65e0\u5904\u4e0d\u5728\u3002\u4f46\u73b0\u5728\u8ba9\u6211\u4eec\u56de\u5230\u6211\u4eec\u7684\u7f16\u7801\u4e16\u754c\u5e76\u63a2\u7d22\u5b83\u3002<\/p><h2 id=\"tab-con-1\" class=\"wp-block-heading\">\u8bed\u6cd5\uff1aVBA IF<\/h2><p> VBA \u4e2d\u6709\u4e09\u79cd\u4e0d\u540c\u7c7b\u578b\u7684 IF \u8bed\u53e5\u3002<\/p><h3 id=\"tab-con-2\" class=\"wp-block-heading\"> 1. \u5982\u679c-\u90a3\u4e48<\/h3><p>IF THEN \u662f IF \u8bed\u53e5\u7684\u6700\u7b80\u5355\u5f62\u5f0f\u3002\u6211\u4eec\u9700\u8981\u505a\u7684\u5c31\u662f\u6307\u5b9a\u4e00\u4e2a\u8981\u68c0\u67e5\u7684\u6761\u4ef6\uff0c\u5982\u679c\u8be5\u6761\u4ef6\u4e3a\u771f\uff0c\u5b83\u5c06\u6267\u884c\u4e00\u9879\u4efb\u52a1\u3002\u4f46\u662f\uff0c\u5982\u679c\u6b64\u6761\u4ef6\u4e3a FALSE\uff0c\u5219\u5b83\u5c06\u4e0d\u6267\u884c\u4efb\u4f55\u64cd\u4f5c\u5e76\u7acb\u5373\u8df3\u7ebf\u3002<\/p><h4 class=\"wp-block-heading\">\u53e5\u6cd5<\/h4><pre class=\"wp-block-code\"> <code class=\"language-visual-basic\" lang=\"visual-basic\">IF condition Then statement[s]<\/code><\/pre><p>\u5728\u4e0a\u9762\u7684\u8bed\u6cd5\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u6307\u5b9a\u8981\u8bc4\u4f30\u7684\u6761\u4ef6\u4ee5\u53ca\u5728\u8be5\u6761\u4ef6\u4e3a TRUE \u65f6\u8981\u6267\u884c\u7684\u4efb\u52a1\u3002<\/p><h4 class=\"wp-block-heading\">\u4f8b\u5b50<\/h4><p class=\"has-text-align-center\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/exceladvisor.org\/wp-content\/uploads\/2023\/08\/vba-if-instruction-utilisant-if-then-macro-code-1.gif\" sizes=\"auto, \" srcset=\"\" alt=\"vba if\u8bed\u53e5\u4f7f\u7528if then\u5b8f\u4ee3\u7801\" width=\"228\" height=\"172\" data-attachment-id=\"7995\"><\/p><p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u68c0\u67e5\u4e86\u5355\u5143\u683c A1 \u662f\u5426\u5305\u542b\u503c 10\uff0c\u5982\u679c\u5305\u542b\uff0c\u8be5\u8bed\u53e5\u5c06\u663e\u793a\u4e00\u4e2a\u6d88\u606f\u6846\uff0c\u5176\u4e2d\u5305\u542b\u6d88\u606f\u201c\u5355\u5143\u683c A1 \u7684\u503c\u4e3a 10\u201d\u3002<\/p><pre class=\"wp-block-code\"> <code class=\"language-visual-basic\" lang=\"visual-basic\">Sub CheckValue() If Range(\"A1\").Value = 10 Then MsgBox (\"Cell A1 has value 10\") End Sub<\/code><\/pre><h3 id=\"tab-con-3\" class=\"wp-block-heading\"> 2. IF-then-else<\/h3><p>\u5982\u679c\u60a8\u5e0c\u671b\u5728\u6761\u4ef6\u4e3a TRUE \u65f6\u6267\u884c\u7279\u5b9a\u4efb\u52a1\uff0c\u5728\u6761\u4ef6\u4e3a FALSE \u65f6\u6267\u884c\u4e0d\u540c\u7684\u4efb\u52a1\uff0c\u5219\u53ef\u4ee5\u4f7f\u7528 IF-Then-Else \u8bed\u53e5\u3002<\/p><h4 class=\"wp-block-heading\">\u53e5\u6cd5<\/h4><pre class=\"wp-block-code\"> <code class=\"language-visual-basic\" lang=\"visual-basic\">IF Condition Then Statement[s] Else Statement[s] End If<\/code><\/pre><p>\u4f7f\u7528\u4e0a\u9762\u7684\u8bed\u6cd5\uff0c\u6211\u4eec\u53ef\u4ee5\u6839\u636e\u6761\u4ef6\u7684\u7ed3\u679c\u6267\u884c\u4e0d\u540c\u7684\u4efb\u52a1\u3002\u5982\u679c\u6761\u4ef6\u4e3a TRUE\uff0c\u5219\u6267\u884c\u201cThen\u201d\u540e\u7684\u8bed\u53e5\uff1b\u5982\u679c\u6761\u4ef6\u4e3a FALSE\uff0c\u5219\u6267\u884c\u201cElse\u201d\u540e\u7684\u8bed\u53e5\u3002<\/p><h4 class=\"wp-block-heading\">\u4f8b\u5b50<\/h4><pre class=\"wp-block-code\"> <code class=\"language-visual-basic\" lang=\"visual-basic\">Sub CheckValue() If Range(\"A1\").Value = \"10\" Then MsgBox (\"Cell A1 has value 10\") Else MsgBox (\"Cell A1 has a value other than 10\") End Sub<\/code><\/pre><div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/exceladvisor.org\/wp-content\/uploads\/2023\/08\/vba-if-instruction-utilisant-le-code-de-macro-if-then-else-1.gif\" sizes=\"\" srcset=\"\" alt=\"vba if\u8bed\u53e5\u4f7f\u7528if then else\u5b8f\u4ee3\u7801\"><\/figure><\/div><p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u6211\u4f7f\u7528 IF-Then-Else \u8bed\u53e5\u6765\u68c0\u67e5\u5355\u5143\u683c A1 \u4e2d\u7684\u503c\u3002<\/p><p>\u5982\u679c\u5355\u5143\u683c A1 \u7684\u503c\u4e3a 10\uff0c\u60a8\u5c06\u6536\u5230\u4e00\u4e2a\u6d88\u606f\u6846\uff0c\u663e\u793a\u201c\u5355\u5143\u683c A1 \u7684\u503c\u4e3a 10\u201d\uff0c\u5982\u679c\u5355\u5143\u683c A1 \u4e2d\u6709\u53e6\u4e00\u4e2a\u503c\uff0c\u60a8\u5c06\u6536\u5230\u4e00\u4e2a\u6d88\u606f\u6846\uff0c\u663e\u793a\u201c\u5355\u5143\u683c A1 \u7684\u503c\u4e0d\u662f10\u201d\u3002\u6240\u4ee5\u8fd9\u91cc\u6211\u4eec\u53ef\u4ee5\u6839\u636e\u6761\u4ef6\u7ed3\u679c\u6267\u884c\u4e0d\u540c\u7684\u4efb\u52a1\u3002<\/p><h3 id=\"tab-con-4\" class=\"wp-block-heading\"> 3. IF-Then-Elseif-Else<\/h3><p>\u8fd9\u662f\u6700\u6709\u7528\u548c\u6700\u91cd\u8981\u7684 IF \u7c7b\u578b\uff0c\u53ef\u5e2e\u52a9\u60a8\u7f16\u5199\u9ad8\u7ea7\u6761\u4ef6\u8bed\u53e5\u3002\u5728\u6b64\u7c7b\u578b\u4e2d\uff0c\u60a8\u53ef\u4ee5\u5728\u8bc4\u4f30\u7b2c\u4e00\u4e2a\u6761\u4ef6\u540e\u6307\u5b9a\u7b2c\u4e8c\u4e2a\u6761\u4ef6\u3002<\/p><h4 class=\"wp-block-heading\">\u53e5\u6cd5<\/h4><pre class=\"wp-block-code\"> <code class=\"language-visual-basic\" lang=\"visual-basic\">IF Condition Then Statement[s] Elseif Condition Then Statement[s] Else Statement[s] End If<\/code><\/pre><p>\u5728\u4e0a\u9762\u7684\u8bed\u6cd5\u4e2d\uff0c\u6211\u4eec\u6709\uff1a<\/p><ol><li>\u6709\u6761\u4ef6\u6765\u8bc4\u4ef7\u3002<\/li><li>\u5982\u679c\u8be5\u6761\u4ef6\u4e3a TURE \u5219\u6267\u884c\u7684\u6307\u4ee4\u3002<\/li><li>\u5982\u679c\u8fd9\u4e2a\u6761\u4ef6\u4e3a FALSE\uff0c\u90a3\u4e48\u6211\u4eec\u9700\u8981\u8bc4\u4f30\u7b2c\u4e8c\u4e2a\u6761\u4ef6\u3002<\/li><li>\u800c\u4e14\uff0c\u5982\u679c\u7b2c\u4e8c\u4e2a\u6761\u4ef6\u4e3a\u771f\uff0c\u6211\u4eec\u5c31\u9700\u8981\u505a\u51fa\u58f0\u660e\u3002<\/li><li>\u4f46\u662f\uff0c\u5982\u679c\u7b2c\u4e00\u4e2a\u548c\u7b2c\u4e8c\u4e2a\u6761\u4ef6\u90fd\u4e3a FALSE\uff0c\u5b83\u5c06\u505a\u51fa\u60a8\u5728\u201cElse\u201d\u4e4b\u540e\u63d0\u5230\u7684\u58f0\u660e\u3002<\/li><\/ol><p>\u800c\u4e14\uff0c\u6700\u597d\u7684\u90e8\u5206\u662f\u60a8\u53ef\u4ee5\u5728\u4ee3\u7801\u4e2d\u4f7f\u7528\u4efb\u610f\u6570\u91cf\u7684\u201cElseif\u201d\u3002\u8fd9\u610f\u5473\u7740\u60a8\u53ef\u4ee5\u5728\u58f0\u660e\u4e2d\u6307\u5b9a\u4efb\u610f\u6570\u91cf\u7684\u6761\u4ef6\u3002<\/p><h4 class=\"wp-block-heading\">\u4f8b\u5b50<\/h4><div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/exceladvisor.org\/wp-content\/uploads\/2023\/08\/vba-if-instruction-utilisant-if-then-elseif-elseif-macro-code-1.gif\" sizes=\"\" srcset=\"\" alt=\"vba if\u8bed\u53e5\u4f7f\u7528if then elseif elseif\u5b8f\u4ee3\u7801\"><\/figure><\/div><pre class=\"wp-block-code\"> <code class=\"language-visual-basic\" lang=\"visual-basic\">Sub check_grade() If Range(\"A2\").Value = \"A\" Then MsgBox \"Very Good\" Else If Range(\"A2\").Value = \"B\" Then MsgBox \"Good\" ElseIf Range(\"A2\").Value = \"C\" Then MsgBox \"Average\" ElseIf Range(\"A2\").Value = \"D\" Then MsgBox \"Poor\" ElseIf Range(\"A2\").Value = \"E\" Then MsgBox \"Very Poor\" Else MsgBox \"Enter Correct Grade\" End Sub<\/code><\/pre><p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u7f16\u5199\u4e86\u4e00\u4e2a\u5b8f\uff0c\u5b83\u5c06\u9996\u5148\u68c0\u67e5\u5355\u5143\u683c A2 \u7684\u503c\u201cA\u201d\uff0c\u5982\u679c\u8be5\u5355\u5143\u683c\u7684\u8bc4\u7ea7\u4e3a\u201cA\u201d\uff0c\u5219\u8be5\u8bed\u53e5\u5c06\u8fd4\u56de\u6d88\u606f\u201cVery Good\u201d\u3002<\/p><p>\u8be5\u6307\u4ee4\u5c06\u9996\u5148\u68c0\u67e5\u5355\u5143\u683c A2 \u7684\u503c\u201cA\u201d\uff0c\u5982\u679c\u8be5\u5355\u5143\u683c\u7684\u8bc4\u7ea7\u4e3a\u201cA\u201d\uff0c\u5219\u8be5\u6307\u4ee4\u5c06\u8fd4\u56de\u6d88\u606f\u201c\u975e\u5e38\u597d\u201d\u3002<\/p><p>\u5e76\u4e14\uff0c\u5982\u679c\u7b2c\u4e00\u4e2a\u6761\u4ef6\u4e3a FALSE\uff0c\u5219\u5b83\u5c06\u8bc4\u4f30\u7b2c\u4e8c\u4e2a\u6761\u4ef6\uff0c\u5e76\u5728\u5c0f\u533a\u8bc4\u7ea7\u4e3a\u201cB\u201d\u65f6\u8fd4\u56de\u6d88\u606f\u201cGood\u201d\u3002<\/p><p>\u5e76\u4e14\uff0c\u5982\u679c\u7b2c\u4e8c\u4e2a\u6761\u4ef6\u4e3a\u5047\uff0c\u5219\u5b83\u5c06\u79fb\u81f3\u7b2c\u4e09\u4e2a\u6761\u4ef6\uff0c\u4f9d\u6b64\u7c7b\u63a8\u3002\u6700\u7ec8\uff0c\u5982\u679c\u6240\u6709\u4e94\u4e2a\u6761\u4ef6\u90fd\u4e3a\u5047\uff0c\u5b83\u5c06\u6267\u884c\u6211\u5728\u5176\u4f59\u6761\u4ef6\u4e4b\u540e\u7f16\u5199\u7684\u4ee3\u7801\u3002<\/p><h2 id=\"tab-con-5\" class=\"wp-block-heading\">\u5728 VBA \u4e2d\u7f16\u5199 IF \u8bed\u53e5\u7684\u79d8\u8bc0<\/h2><p>\u73b0\u5728\u60a8\u5df2\u7ecf\u4e86\u89e3\u4e86 IS \u7684\u6240\u6709\u7c7b\u578b\uff0c\u5e76\u4e14\u8fd8\u53ef\u4ee5\u6839\u636e\u9700\u8981\u6267\u884c\u7684\u4efb\u52a1\u9009\u62e9\u4e00\u79cd\u7c7b\u578b\u3002\u8ba9\u6211\u544a\u8bc9\u4f60\u4e00\u4e2a\u79d8\u5bc6\u3002<\/p><h3 id=\"tab-con-6\" class=\"wp-block-heading\">\u5355\u884c IF \u8bed\u53e5\u4e0e\u5757 IF \u8bed\u53e5<\/h3><p>\u60a8\u53ef\u4ee5\u7528\u4e24\u79cd\u4e0d\u540c\u7684\u65b9\u5f0f\u7f16\u5199 IF \u8bed\u53e5\uff0c\u4e24\u8005\u5404\u6709\u4f18\u70b9\u548c\u7f3a\u70b9\u3002\u770b\u7740\u3002<\/p><h4 class=\"wp-block-heading\"> 1. \u4e00\u884c\u8bed\u53e5<\/h4><p>\u5982\u679c\u4f7f\u7528 IF-Then \u8bed\u53e5\uff0c\u90a3\u4e48\u4e00\u884c\u8bed\u53e5\u662f\u5b8c\u7f8e\u7684\u3002\u4f7f\u7528\u884c\u8bed\u53e5\u7684\u57fa\u7840\u662f\u5c06\u6240\u6709\u4ee3\u7801\u5199\u5728\u4e00\u884c\u4e0a\u3002<\/p><pre class=\"wp-block-code\"> <code class=\"language-visual-basic\" lang=\"visual-basic\">If A1 = 10 Then Msgbox(\"Cell A1 has value 10\")<\/code><\/pre><p>\u5728\u4e0a\u9762\u7684\u8bed\u53e5\u4e2d\uff0c\u6211\u4eec\u7f16\u5199\u4e86\u4e00\u4e2a IF \u8bed\u53e5\u6765\u8bc4\u4f30\u5355\u5143\u683c A1 \u7684\u503c\u662f\u5426\u4e3a 10\uff0c\u7136\u540e\u5b83\u4f1a\u663e\u793a\u4e00\u4e2a\u6d88\u606f\u6846\u3002\u4f7f\u7528\u4e00\u884c\u8bed\u53e5\u7684\u6700\u4f73\u5b9e\u8df5\u662f\u5f53\u60a8\u9700\u8981\u7f16\u5199\u7b80\u5355\u7684\u4ee3\u7801\u65f6\u3002\u4f7f\u7528\u4e00\u884c\u4ee3\u7801\u8fdb\u884c\u590d\u6742\u4e14\u957f\u7684\u58f0\u660e\u662f\u5f88\u96be\u7406\u89e3\u7684\u3002<\/p><p class=\"qt-tip\"><strong>\u5feb\u901f\u63d0\u793a\uff1a<\/strong>\u7f16\u5199\u5355\u884c\u4ee3\u7801\u65f6\uff0c\u4e0d\u9700\u8981\u4f7f\u7528 Endif \u6765\u5b8c\u6210\u8bed\u53e5\u3002<\/p><h4 class=\"wp-block-heading\"> 2. \u533a\u5757\u58f0\u660e<\/h4><p>\u5f53\u60a8\u60f3\u4ee5\u4e00\u79cd\u4f53\u9762\u4e14\u6613\u4e8e\u7406\u89e3\u7684\u65b9\u5f0f\u7f16\u5199\u4ee3\u7801\u65f6\uff0cBlock \u8bed\u53e5\u662f\u5b8c\u7f8e\u7684\u9009\u62e9\u3002\u5f53\u60a8\u7f16\u5199\u5757\u8bed\u53e5\u65f6\uff0c\u60a8\u53ef\u4ee5\u5728\u5b8f\u4e2d\u4f7f\u7528\u591a\u884c\uff0c\u4ece\u800c\u4e3a\u60a8\u63d0\u4f9b\u6574\u6d01\u5e72\u51c0\u7684\u4ee3\u7801\u3002<\/p><pre class=\"wp-block-code\"> <code class=\"language-visual-basic\" lang=\"visual-basic\">Sub check_value() If Range(\u201cA1\u201d).Value = \u201c10\u201d Then MsgBox (\"Cell A1 has value 10\") Else MsgBox (\"Cell A1 has a value other than 10\") End If End Sub<\/code><\/pre><p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u5728\u5757\u4e2d\u7f16\u5199\u4e86 IF-Then-Else \u8bed\u53e5\u3002\u800c\u4e14\uff0c\u60a8\u53ef\u4ee5\u770b\u5230\u5b83\u5f88\u5bb9\u6613\u9605\u8bfb\uff0c\u751a\u81f3\u5f88\u5bb9\u6613\u8c03\u8bd5\u3002<\/p><p>\u5f53\u7f16\u5199\u590d\u6742\u7684\u6307\u4ee4\u65f6\uff08\u9605\u8bfb\u672c\u6307\u5357\u540e\u60a8\u80af\u5b9a\u4f1a\u8fd9\u6837\u505a\uff09\uff0c\u5757\u6307\u4ee4\u603b\u662f\u597d\u7684\u3002\u800c\u4e14\uff0c\u5728\u7f16\u5199\u5d4c\u5957 If \u8bed\u53e5\u65f6\uff0c\u60a8\u8fd8\u53ef\u4ee5\u5728\u884c\u4e2d\u6dfb\u52a0\u7f29\u8fdb\u4ee5\u4fdd\u6301\u6e05\u6670\u3002<\/p><p class=\"qt-tip\"><strong>\u5feb\u901f\u63d0\u793a<\/strong>\u2013 \u5f53\u60a8\u4f7f\u7528 IF-Then-Elseif-Else \u65f6\uff0c\u60a8\u53ef\u4ee5\u5728\u4ee3\u7801\u672b\u5c3e\u4f7f\u7528 Else \u6765\u5ffd\u7565\u8be5\u5f02\u5e38\u3002\u5f53\u8bed\u53e5\u4e2d\u6ca1\u6709\u4e00\u4e2a\u6761\u4ef6\u4e0d\u4e3a TRUE \u4e14\u4e0d\u9700\u8981\u6267\u884c\u4efb\u4f55\u4efb\u52a1\u65f6\uff0c\u8fd9\u975e\u5e38\u6709\u7528\u3002<\/p><h2 id=\"tab-con-7\" class=\"wp-block-heading\"> 8\u4e2a\u5177\u4f53\u4f8b\u5b50<\/h2><p>\u6211\u5728\u8fd9\u91cc\u5217\u51fa\u4e86\u4e00\u4e9b\u7b80\u5355\u4f46\u6709\u7528\u7684\u793a\u4f8b\uff0c\u60a8\u53ef\u4ee5\u9075\u5faa\u3002<\/p><h3 id=\"tab-con-8\" class=\"wp-block-heading\"> 1. \u5d4c\u5957 IF<\/h3><p> IF \u8bed\u53e5\u6700\u597d\u7684\u90e8\u5206\u662f\u60a8\u53ef\u4ee5\u521b\u5efa\u5d4c\u5957\u8bed\u53e5\u3002\u60a8\u53ef\u4ee5\u5c06\u7b2c\u4e8c\u4e2a\u6761\u4ef6\u6dfb\u52a0\u5230\u7b2c\u4e00\u4e2a\u6761\u4ef6\u3002 <\/p><div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/exceladvisor.org\/wp-content\/uploads\/2023\/08\/ecriture-imbrication-si-avec-vba-if-instruction-1.gif\" sizes=\"\" srcset=\"\" alt=\"\u7528vba if\u8bed\u53e5\u7f16\u5199\u5d4c\u5957if\"><\/figure><\/div><pre class=\"wp-block-code\"> <code class=\"language-visual-basic\" lang=\"visual-basic\">Sub NestIF() Dim res As Long res = MsgBox(\"Do you want to save this file?\", vbYesNo, \"Save File\") If res = vbYes Then 'start of first IF statement If ActiveWorkbook.Saved &lt;&gt; True Then 'start of second IF statement. ActiveWorkbook.SaveMsgBox (\"Workbook Saved\") Else MsgBox \"This workbook is already saved\" End If 'end of second IF statement Else MsgBox \"Make Sure to save it later\" End If ' end of first IF statement End Sub<\/code><\/pre><p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u4e86\u5d4c\u5957 IF \u8bed\u53e5\u3002\u5f53\u60a8<a href=\"https:\/\/exceladvisor.org\/cn\/\u6267\u884c\u5b8f2\/\">\u8fd0\u884c\u6b64\u5b8f<\/a>\u65f6\uff0c\u60a8<a href=\"https:\/\/exceladvisor.org\/cn\/vba\u6d88\u606f\u6846\/\">\u5c06\u770b\u5230\u4e00\u4e2a\u5e26\u6709\u201c\u786e\u5b9a\u201d\u548c\u201c\u53d6\u6d88\u201d\u9009\u9879\u7684\u6d88\u606f\u6846<\/a>\u3002\u4e4b\u540e\u6761\u4ef6\u8bed\u53e5\u7684\u5de5\u4f5c\u5f00\u59cb\u3002<\/p><p>\u9996\u5148\uff0c\u5b83\u5c06\u8bc4\u4f30\u60a8\u5355\u51fb\u7684\u6309\u94ae\u3002\u5982\u679c\u60a8\u5355\u51fb\u201c\u662f\u201d\uff0c\u5219\u5d4c\u5957\u5b83\u4ee5\u8bc4\u4f30\u60a8\u7684\u7535\u5b50\u8868\u683c\u662f\u5426\u5df2\u4fdd\u5b58\u3002<\/p><p>\u5982\u679c\u60a8\u7684\u5de5\u4f5c\u7c3f\u672a\u4fdd\u5b58\uff0c\u5b83\u5c06\u4fdd\u5b58\u5b83\u5e76\u4e14\u60a8\u5c06\u6536\u5230\u4e00\u6761\u6d88\u606f\u3002\u800c\u4e14\uff0c\u5982\u679c\u5de5\u4f5c\u7c3f\u5df2\u4fdd\u5b58\uff0c\u5b83\u5c06\u663e\u793a\u4e00\u6761\u6709\u5173\u5b83\u7684\u6d88\u606f\u3002<\/p><p>\u4f46\u662f\uff0c\u5982\u679c\u60a8\u5355\u51fb\u8be5\u6309\u94ae\uff0c\u7b2c\u4e00\u4e2a\u5b8f\u7684\u6761\u4ef6\u5c06\u4e3a FALSE\uff0c\u5e76\u4e14\u7a0d\u540e\u60a8\u53ea\u4f1a\u6536\u5230\u4e00\u6761\u6d88\u606f\u4ee5\u4fdd\u5b58\u60a8\u7684\u4e66\u7c4d\u3002<\/p><p>\u8fd9\u6bb5\u4ee3\u7801\u7684\u57fa\u672c\u601d\u60f3\u662f\uff0c\u7b2c\u4e8c\u4e2a\u6761\u4ef6\u5b8c\u5168\u53d6\u51b3\u4e8e\u7b2c\u4e00\u4e2a\u6761\u4ef6\uff0c\u5982\u679c\u7b2c\u4e00\u4e2a\u6761\u4ef6\u4e3a FALSE\uff0c\u5219\u4e0d\u4f1a\u8bc4\u4f30\u7b2c\u4e8c\u4e2a\u6761\u4ef6\u3002<\/p><p>\u4e86\u89e3\u6709\u5173<strong><a href=\"https:\/\/exceladvisor.org\/cn\/\u5d4c\u5957\u5982\u679c\/\">\u5d4c\u5957 IF \u7684<\/a><\/strong>\u66f4\u591a\u4fe1\u606f<\/p><h3 id=\"tab-con-9\" class=\"wp-block-heading\">2. \u4f7f\u7528 IF \u548c GoTo \u521b\u5efa\u5faa\u73af<\/h3><p>\u60a8\u8fd8\u53ef\u4ee5\u4f7f\u7528 goto \u548c IF \u521b\u5efa\u5faa\u73af\u3002\u5927\u591a\u6570\u7a0b\u5e8f\u5458\u907f\u514d\u4ee5\u8fd9\u79cd\u65b9\u5f0f\u7f16\u5199\u5faa\u73af\uff0c\u56e0\u4e3a\u6211\u4eec\u6709<a href=\"https:\/\/exceladvisor.org\/cn\/\u5faa\u73af\/\">\u66f4\u597d\u7684\u5faa\u73af\u65b9\u6cd5<\/a>\u3002\u4f46\u5b66\u4e60\u5982\u4f55\u505a\u5230\u8fd9\u4e00\u70b9\u5e76\u6ca1\u6709\u4ec0\u4e48\u574f\u5904\u3002<\/p><pre class=\"wp-block-code\"> <code class=\"language-visual-basic\" lang=\"visual-basic\">Sub auto_open() Alert: If InputBox(\"Enter Username\") &lt;&gt; \"Puneet\" Then GoTo Alert Else MsgBox \"Welcome\" End If End Sub<\/code><\/pre><p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u6761\u4ef6\u8bed\u53e5\u6765\u521b\u5efa\u5faa\u73af\u3002\u6211\u4eec\u4f7f\u7528 auto_open \u4f5c\u4e3a\u5b8f\u540d\u79f0\uff0c\u4ee5\u4fbf\u6bcf\u6b21\u6709\u4eba\u6253\u5f00\u6587\u4ef6\u65f6\uff0c\u90fd\u4f1a\u8fd0\u884c\u8be5\u5b8f\u3002<\/p><p>\u7528\u6237\u5fc5\u987b\u8f93\u5165\u7528\u6237\u540d\uff0c\u5982\u679c\u8be5\u7528\u6237\u540d\u4e0d\u7b49\u4e8e\u201cPuneet\u201d\uff0c\u5b83\u5c06\u91cd\u590d\u4ee3\u7801\u5e76\u518d\u6b21\u663e\u793a\u8f93\u5165\u6846\u3002\u800c\u4e14\uff0c\u5982\u679c\u60a8\u8f93\u5165\u6b63\u786e\u7684\u6587\u672c\uff0c\u5b83\u5c06\u80fd\u591f\u8bbf\u95ee\u8be5\u6587\u4ef6\u3002<\/p><h3 id=\"tab-con-10\" class=\"wp-block-heading\"> 3. \u68c0\u67e5\u5355\u5143\u683c\u662f\u5426\u5305\u542b\u6570\u5b57<\/h3><p>\u8fd9\u91cc\u6211\u4eec\u4f7f\u7528\u4e86\u4e00\u4e2a\u6761\u4ef6\u6765\u68c0\u67e5<a href=\"https:\/\/exceladvisor.org\/cn\/\u6d3b\u8dc3\u7ec6\u80de\/\">\u6d3b\u52a8\u5355\u5143\u683c<\/a>\u662f\u5426\u5305\u542b\u6570\u503c\u3002 <\/p><div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/exceladvisor.org\/wp-content\/uploads\/2023\/08\/utiliser-linstruction-vba-if-pour-verifier-le-nombre-dans-la-cellule-1.gif\" sizes=\"\" srcset=\"\" alt=\"\u4f7f\u7528vba if\u8bed\u53e5\u68c0\u67e5\u5355\u5143\u683c\u4e2d\u7684\u6570\u5b57\"><\/figure><\/div><pre class=\"wp-block-code\"> <code class=\"language-visual-basic\" lang=\"visual-basic\">Sub check_number() If IsNumeric(Range(\"B2\").Value) Then MsgBox \"Yes, active cell has a number.\" Else MsgBox \"No, active cell hasn't a number.\" End If End Sub<\/code><\/pre><p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u6211\u4f7f\u7528 VBA \u4e2d\u7684<a href=\"https:\/\/exceladvisor.org\/cn\/\u662f\u6570\u5b57\u7684\/\">isnumeric \u51fd\u6570<\/a>\u7f16\u5199\u4e86\u4e00\u4e2a\u6761\u4ef6\uff0c\u8be5\u51fd\u6570\u4e0e\u5de5\u4f5c\u8868\u4e2d\u7684\u6570\u5b57\u51fd\u6570\u76f8\u540c\uff0c\u7528\u4e8e\u68c0\u67e5\u5355\u5143\u683c\u7684\u503c\u662f\u5426\u4e3a\u6570\u5b57\u3002<\/p><p>\u5982\u679c\u8be5\u503c\u4e3a\u6570\u5b57\uff0c\u5b83\u5c06\u8fd4\u56de TRUE\uff0c\u5e76\u4e14\u60a8\u5c06\u6536\u5230\u4e00\u6761\u201c\u662f\uff0c\u6d3b\u52a8\u5355\u5143\u683c\u6709\u4e00\u4e2a\u6570\u503c\u201d\u6d88\u606f\u3002\u800c\u4e14\uff0c\u5982\u679c\u8be5\u503c\u4e0d\u662f\u6570\u5b57\uff0c\u60a8\u5c06\u6536\u5230\u201c\u6d3b\u52a8\u5355\u5143\u683c\u4e2d\u6ca1\u6709\u6570\u5b57\u503c\u201d\u6d88\u606f\u3002<\/p><h3 id=\"tab-con-11\" class=\"wp-block-heading\"> 4. \u5c06 OR \u548c AND \u4e0e IF \u7ed3\u5408\u4f7f\u7528<\/h3><p>\u4f7f\u7528<strong><a href=\"https:\/\/exceladvisor.org\/cn\/\u5982\u679c\u6216\/\">IF OR\uff0c<\/a><\/strong>\u60a8\u53ef\u4ee5\u6307\u5b9a\u4e24\u4e2a\u6216\u591a\u4e2a\u6761\u4ef6\uff0c\u5e76\u5728\u6240\u6709\u6761\u4ef6\u4e2d\u81f3\u5c11\u6709\u4e00\u4e2a\u6761\u4ef6\u4e3a TRUE \u65f6\u6267\u884c\u4e00\u9879\u4efb\u52a1\u3002<\/p><pre class=\"wp-block-code\"> <code class=\"language-visual-basic\" lang=\"visual-basic\">Sub UsingOR() If Range(\"A1\") &lt; 70 Or Range(\"B1\") &lt; 70 Then MsgBox \"You Are Pass\" Else If Range(\"A1\") &lt; 40 And Range(\"B1\") &lt; 40 Then MsgBox \"You Are Pass\" Else MsgBox \"You Are Fail\" End If End If End Sub<\/code><\/pre><p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u7b2c 2 \u884c\uff0c\u6211\u4eec\u6709\u4e24\u4e2a\u4f7f\u7528 OR \u7684\u6761\u4ef6\u3002\u5982\u679c\u5b66\u751f\u5728\u4efb\u4f55\u79d1\u76ee\u4e2d\u83b7\u5f97 70 \u5206\uff0c\u7ed3\u679c\u5c06\u4e3a\u201c\u53ca\u683c\u201d\u3002\u5728\u7b2c 7 \u884c\u4e2d\uff0c\u6211\u4eec\u6709\u4e24\u4e2a\u4f7f\u7528 AND \u8fd0\u7b97\u7b26\u7684\u6761\u4ef6\u3002\u5982\u679c\u5b66\u751f\u4e24\u79d1\u5747\u83b7\u5f97 40 \u5206\u4ee5\u4e0a\uff0c\u5219\u6210\u7ee9\u4e3a\u201c\u53ca\u683c\u201d\u3002<\/p><p>\u4f7f\u7528<strong><a href=\"https:\/\/exceladvisor.org\/cn\/\u5982\u679c\u548c\/\">IF AND\uff0c<\/a><\/strong>\u60a8\u53ef\u4ee5\u6307\u5b9a\u591a\u4e2a\u6761\u4ef6\uff0c\u5e76\u5728\u6240\u6709\u6761\u4ef6\u5747\u4e3a TRUE \u65f6\u6267\u884c\u4efb\u52a1\u3002<\/p><h3 id=\"tab-con-12\" class=\"wp-block-heading\"> 5. Not \u4e0e IF \u4e00\u8d77\u4f7f\u7528<\/h3><p>\u901a\u8fc7\u5728\u6761\u4ef6\u4e2d\u4f7f\u7528 NOT\uff0c\u60a8\u53ef\u4ee5\u5c06 TRUE \u66f4\u6539\u4e3a FALSE\uff0c\u5c06 FALSE \u66f4\u6539\u4e3a TRUE\u3002<\/p><p> <a href=\"https:\/\/exceladvisor.org\/cn\/\u5426\u5219\/\"><strong>VBA \u5982\u679c\u5426<\/strong><\/a><\/p><pre class=\"wp-block-code\"> <code class=\"language-visual-basic\" lang=\"visual-basic\">Sub IF_Not() If Range(\u201cD1\u201d) &lt;= 40 And Not Range(\u201cE1\u201d) = \u201cE\u201d Then MsgBox \"You Are Pass.\" Else MsgBox \"You Are Fail.\" End If End Sub<\/code><\/pre><p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u5728\u6761\u4ef6\u4e2d\u4f7f\u7528\u4e86 NOT\u3002\u6211\u4eec\u6709\u4e24\u4e2a\u5355\u5143\u683c\uff0c\u5176\u4e2d\u5305\u542b\u53d7\u8bd5\u8005\u7684\u5206\u6570\u3002\u5728\u4e00\u4e2a\u5355\u5143\u683c\u4e2d\uff0c\u5206\u6570\u4ee5\u6570\u5b57\u8868\u793a\uff0c\u800c\u5728\u53e6\u4e00\u4e2a\u5355\u5143\u683c\u4e2d\uff0c\u5206\u6570\u4ee5\u7b49\u7ea7\u8868\u793a\u3002<\/p><ul><li>\u5982\u679c\u5b66\u751f\u7b2c\u4e00\u95e8\u79d1\u76ee\u6210\u7ee9\u9ad8\u4e8e 40 \u5206\uff0c\u7b2c\u4e8c\u95e8\u79d1\u76ee\u6210\u7ee9\u9ad8\u4e8e E\uff0c\u5219\u4e3a\u201c\u53ca\u683c\u201d\u3002<\/li><li>\u5982\u679c\u5b66\u751f\u7b2c\u4e00\u95e8\u79d1\u76ee\u6210\u7ee9\u9ad8\u4e8e 40 \u5206\uff0c\u7b2c\u4e8c\u95e8\u79d1\u76ee\u6210\u7ee9\u9ad8\u4e8e E\uff0c\u5219\u4e3a\u201c\u53ca\u683c\u201d\u3002<\/li><\/ul><p>\u56e0\u6b64\uff0c\u6bcf\u5f53\u5b66\u751f\u7684\u6210\u7ee9\u9ad8\u4e8e 40 \u4e14\u6210\u7ee9\u4e0d\u662f E \u65f6\uff0c\u6211\u4eec\u90fd\u4f1a\u6536\u5230\u201c\u60a8\u901a\u8fc7\u201d\u6216\u201c\u60a8\u4e0d\u53ca\u683c\u201d\u6d88\u606f\u3002<\/p><h3 id=\"tab-con-13\" class=\"wp-block-heading\"> 6. \u5e26\u6709\u590d\u9009\u6846\u7684 IF \u58f0\u660e<\/h3><p>\u73b0\u5728\u6211\u4eec\u4f7f\u7528\u590d\u9009\u6846\u6765\u8fd0\u884c\u5b8f\u3002 <\/p><div class=\"wp-block-image\"><figure class=\"aligncenter is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/exceladvisor.org\/wp-content\/uploads\/2023\/08\/en-utilisant-linstruction-vba-if-avec-case-a-cocher-1.gif\" sizes=\"auto, \" srcset=\"\" alt=\"\u4f7f\u7528\u5e26\u6709\u590d\u9009\u6846\u7684 vba if \u8bed\u53e5\" width=\"683\" height=\"153\"><\/figure><\/div><pre class=\"wp-block-code\"> <code class=\"language-visual-basic\" lang=\"visual-basic\">Sub ship_as_bill() If Range(\"D15\") = True Then Range(\"D17:D21\") = Range(\"C17:C21\") Else If Range(\u201cD15\u201d) = False Then Range(\"D17:D21\").ClearContents Else MsgBox (\u201cError!\u201d) End If End If End Sub<\/code><\/pre><p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528 IF \u8bed\u53e5\u521b\u5efa\u4e00\u4e2a\u6761\u4ef6\uff0c\u5373\u5982\u679c\u9009\u4e2d\u8be5\u590d\u9009\u6846\uff0c\u5219\u8303\u56f4 D17:D21 \u7b49\u4e8e\u8303\u56f4 C17:C21\u3002\u5e76\u4e14\uff0c\u5982\u679c\u672a\u9009\u4e2d\u8be5<a href=\"https:\/\/exceladvisor.org\/cn\/\u590d\u9009\u6846\/\">\u6846<\/a>\uff0c\u5219\u8303\u56f4 D17:D21 \u5c06\u4e3a\u7a7a\u3002<\/p><p>\u4f7f\u7528\u8fd9\u79cd\u6280\u672f\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u5e10\u5355\u5730\u5740\u4f5c\u4e3a\u9001\u8d27\u5730\u5740\uff0c\u5982\u679c\u6211\u4eec\u9700\u8981\u5176\u4ed6\u4efb\u4f55\u5185\u5bb9\uff0c\u6211\u4eec\u53ef\u4ee5\u624b\u52a8\u8f93\u5165\u5730\u5740\u3002<\/p><h3 id=\"tab-con-14\" class=\"wp-block-heading\"> 7. \u68c0\u67e5\u5355\u5143\u683c\u662f\u5426\u5408\u5e76<\/h3><p>\u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u7f16\u5199\u4e00\u4e2a\u6761\u4ef6\uff0c\u4ee5\u4fbf\u5728\u5408\u5e76\u6d3b\u52a8\u5355\u5143\u683c\u65f6\u63a5\u6536\u8b66\u62a5\u3002 <\/p><div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/exceladvisor.org\/wp-content\/uploads\/2023\/08\/verifier-si-une-cellule-est-fusionnee-a-laide-de-linstruction-vba-if-1.gif\" sizes=\"\" srcset=\"\" alt=\"\u4f7f\u7528 vba if \u8bed\u53e5\u68c0\u67e5\u5355\u5143\u683c\u662f\u5426\u5408\u5e76\"><\/figure><\/div><pre class=\"wp-block-code\"> <code class=\"language-visual-basic\" lang=\"visual-basic\">Sub MergeCellCheck() If ActiveCell.MergeCells Then MsgBox \"Active Cell Is Merged\" Else MsgBox \"Active Cell Is Not Merged\" End If End Sub<\/code><\/pre><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<a href=\"https:\/\/exceladvisor.org\/cn\/\u5408\u5e76\/\">\u5408\u5e76\u5355\u5143\u683c<\/a>\u6765\u68c0\u67e5\u6d3b\u52a8\u5355\u5143\u683c\u662f\u5426\u5408\u5e76\u3002\u5982\u679c\u5408\u5e76<a href=\"https:\/\/exceladvisor.org\/cn\/\u6d3b\u8dc3\u7ec6\u80de1\/\">\u6d3b\u52a8\u5355\u5143<\/a>\u683c\uff0c\u5219\u6761\u4ef6\u5c06\u8fd4\u56de<a href=\"https:\/\/exceladvisor.org\/cn\/vba\u6d88\u606f\u6846\/\">\u6b64\u8b66\u62a5<\/a>\u3002<\/p><h3 id=\"tab-con-15\" class=\"wp-block-heading\"> 8. \u5982\u679c\u5355\u5143\u683c\u4e3a\u7a7a\uff0c\u5219\u5220\u9664\u6574\u884c<\/h3><p>\u8fd9\u91cc\u6211\u4eec\u4f7f\u7528 IF \u6765\u68c0\u67e5\u4e00\u884c\u662f\u5426\u4e3a\u7a7a\u3002\u5e76\u4e14\uff0c\u5982\u679c\u8be5\u884c\u4e3a\u7a7a\uff0c\u5219\u8be5\u8bed\u53e5\u5c06\u5220\u9664\u8be5\u7279\u5b9a\u884c\u3002<\/p><pre class=\"wp-block-code\"> <code class=\"language-visual-basic\" lang=\"visual-basic\">Sub DeleteRow() If Application.CountA(ActiveCell.EntireRow) = 0 Then ActiveCell.EntireRow.Delete Else MsgBox Application.CountA(ActiveCell.EntireRow) &amp; \"Cell(s) have values in this row\" End If End Sub<\/code><\/pre><p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u5b83\u5c06\u9996\u5148\u68c0\u67e5\u5177\u6709\u503c\u7684\u5355\u5143\u683c\u3002\u5982\u679c\u5177\u6709\u503c\u7684\u5355\u5143\u683c\u6570\u91cf\u4e3a\u96f6\uff0c\u5219\u6761\u4ef6\u5c06\u5220\u9664\u6d3b\u52a8\u884c\uff0c\u5426\u5219\u8fd4\u56de\u6307\u793a\u5177\u6709\u503c\u7684\u5355\u5143\u683c\u6570\u91cf\u7684\u8b66\u62a5\u3002<\/p><h2 class=\"wp-block-heading\">\u7ed3\u8bba<\/h2><p>\u6b63\u5982\u6211\u6240\u8bf4\uff0c\u8fd9\u662f VBA \u6700\u91cd\u8981\u7684\u90e8\u5206\u4e4b\u4e00\uff0c\u5982\u679c\u4f60\u60f3\u638c\u63e1 VBA\uff0c\u5c31\u5fc5\u987b\u5b66\u4e60\u5b83\u3002\u4f7f\u7528 IF \u8bed\u53e5\uff0c\u60a8\u53ef\u4ee5\u7f16\u5199\u7b80\u5355\u4ee3\u7801\uff0c\u4e5f\u53ef\u4ee5\u7f16\u5199\u590d\u6742\u4ee3\u7801\u3002\u60a8\u8fd8\u53ef\u4ee5\u4f7f\u7528\u903b\u8f91\u8fd0\u7b97\u7b26\u5e76\u7f16\u5199\u5d4c\u5957\u6761\u4ef6\u3002<\/p><p>\u6211\u5e0c\u671b\u672c\u6307\u5357\u53ef\u4ee5\u5e2e\u52a9\u60a8\u7f16\u5199\u66f4\u597d\u7684\u4ee3\u7801\u3002<\/p><p>\u73b0\u5728\u544a\u8bc9\u6211\u8fd9\u4e2a\u3002\u60a8\u7ecf\u5e38\u5728 VBA \u4e2d\u7f16\u5199\u6761\u4ef6\u5417\uff1f\u4f60\u5199\u4ec0\u4e48\u6837\u7684\u4ee3\u7801\uff1f\u8bf7\u5728\u8bc4\u8bba\u90e8\u5206\u4e0e\u6211\u5206\u4eab\u60a8\u7684\u770b\u6cd5\u3002\u5e76\u4e14\u4e0d\u8981\u5fd8\u8bb0\u4e0e\u60a8\u7684\u670b\u53cb\u5206\u4eab\u672c\u6307\u5357\u3002<\/p><div class=\"gb-container gb-container-4db6181c gb-container-mt\"> <a class=\"gb-button gb-button-c5897111 gb-button-text gb-button-mt-button\" href=\"https:\/\/exceladvisor.org\/cn\/\u7ef4\u5df4\/\">\u4ec0\u4e48\u662fVBA<\/a><h2 class=\"gb-headline gb-headline-665e5f6b gb-headline-text gb-headline-mt-heading\">\u76f8\u5173\u6559\u7a0b<\/h2><div class=\"gb-grid-wrapper gb-grid-wrapper-a20baf7c gb-grid-wrapper-mt-grid\"><div class=\"gb-grid-column gb-grid-column-65ddf67e\"><div class=\"gb-container gb-container-65ddf67e\"><ul><li> <a href=\"https:\/\/exceladvisor.org\/cn\/\u51fa\u53bb\u5982\u679c\/\">VBA \u9000\u51fa\u5982\u679c<\/a><\/li><li><a href=\"https:\/\/exceladvisor.org\/cn\/\u5982\u679c\u548c\/\">VBA \u5982\u679c\u548c<\/a><\/li><li><a href=\"https:\/\/exceladvisor.org\/cn\/\u5426\u5219\/\">VBA \u5982\u679c\u5426<\/a><\/li><li><a href=\"https:\/\/exceladvisor.org\/cn\/\u5982\u679c\u6216\/\">VBA \u5982\u679c\u6216<\/a><\/li><li><a href=\"https:\/\/exceladvisor.org\/cn\/\u5d4c\u5957\u5982\u679c\/\">VBA \u5d4c\u5957 IF<\/a> <\/li><\/ul><\/div><\/div><div class=\"gb-grid-column gb-grid-column-50067b57\"><div class=\"gb-container gb-container-50067b57\"><\/div><\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"ub_ctt_via":"","footnotes":""},"class_list":["post-677","page","type-page","status-publish","hentry"],"featured_image_src":null,"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u25b7 \u5982\u4f55\u5728VBA\u4e2d\u4f7f\u7528IF\u8bed\u53e5\u548cELSE\uff1f<\/title>\n<meta name=\"description\" content=\"\u6761\u4ef6\u65e0\u5904\u4e0d\u5728\u3002\u5f53\u6d89\u53ca VBA \u7f16\u7801\u65f6\uff0c\u6761\u4ef6\u662f\u6700\u91cd\u8981\u7684\u4e8b\u60c5\u4e4b\u4e00\u3002\u5982\u679c\u4f60\u60f3\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/exceladvisor.org\/cn\/\u5982\u679c-2\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u25b7 \u5982\u4f55\u5728VBA\u4e2d\u4f7f\u7528IF\u8bed\u53e5\u548cELSE\uff1f\" \/>\n<meta property=\"og:description\" content=\"\u6761\u4ef6\u65e0\u5904\u4e0d\u5728\u3002\u5f53\u6d89\u53ca VBA \u7f16\u7801\u65f6\uff0c\u6761\u4ef6\u662f\u6700\u91cd\u8981\u7684\u4e8b\u60c5\u4e4b\u4e00\u3002\u5982\u679c\u4f60\u60f3\" \/>\n<meta property=\"og:url\" content=\"https:\/\/exceladvisor.org\/cn\/\u5982\u679c-2\/\" \/>\n<meta property=\"og:site_name\" content=\"Excel Advisor\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-10T11:49:33+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/exceladvisor.org\/wp-content\/uploads\/2023\/08\/en-utilisant-le-code-dinstruction-VBA-IF-dans-Excel.png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/exceladvisor.org\/cn\/%e5%a6%82%e6%9e%9c-2\/\",\"url\":\"https:\/\/exceladvisor.org\/cn\/%e5%a6%82%e6%9e%9c-2\/\",\"name\":\"\u25b7 \u5982\u4f55\u5728VBA\u4e2d\u4f7f\u7528IF\u8bed\u53e5\u548cELSE\uff1f\",\"isPartOf\":{\"@id\":\"https:\/\/exceladvisor.org\/cn\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/exceladvisor.org\/cn\/%e5%a6%82%e6%9e%9c-2\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/exceladvisor.org\/cn\/%e5%a6%82%e6%9e%9c-2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/exceladvisor.org\/wp-content\/uploads\/2023\/08\/en-utilisant-le-code-dinstruction-VBA-IF-dans-Excel.png\",\"datePublished\":\"2023-09-28T18:49:51+00:00\",\"dateModified\":\"2023-12-10T11:49:33+00:00\",\"description\":\"\u6761\u4ef6\u65e0\u5904\u4e0d\u5728\u3002\u5f53\u6d89\u53ca VBA \u7f16\u7801\u65f6\uff0c\u6761\u4ef6\u662f\u6700\u91cd\u8981\u7684\u4e8b\u60c5\u4e4b\u4e00\u3002\u5982\u679c\u4f60\u60f3\",\"breadcrumb\":{\"@id\":\"https:\/\/exceladvisor.org\/cn\/%e5%a6%82%e6%9e%9c-2\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/exceladvisor.org\/cn\/%e5%a6%82%e6%9e%9c-2\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/exceladvisor.org\/cn\/%e5%a6%82%e6%9e%9c-2\/#primaryimage\",\"url\":\"https:\/\/exceladvisor.org\/wp-content\/uploads\/2023\/08\/en-utilisant-le-code-dinstruction-VBA-IF-dans-Excel.png\",\"contentUrl\":\"https:\/\/exceladvisor.org\/wp-content\/uploads\/2023\/08\/en-utilisant-le-code-dinstruction-VBA-IF-dans-Excel.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/exceladvisor.org\/cn\/%e5%a6%82%e6%9e%9c-2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u5bb6\",\"item\":\"https:\/\/exceladvisor.org\/cn\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u5982\u4f55\u5728vba\u4e2d\u4f7f\u7528if\u8bed\u53e5\u548celse\uff1f\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/exceladvisor.org\/cn\/#website\",\"url\":\"https:\/\/exceladvisor.org\/cn\/\",\"name\":\"Excel Advisor\",\"description\":\"\u60a8\u7684\u6570\u636e\u7edf\u6cbb\u7ec8\u6781\u6307\u5357\",\"publisher\":{\"@id\":\"https:\/\/exceladvisor.org\/cn\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/exceladvisor.org\/cn\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/exceladvisor.org\/cn\/#organization\",\"name\":\"Excel Advisor\",\"url\":\"https:\/\/exceladvisor.org\/cn\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/exceladvisor.org\/cn\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/exceladvisor.org\/cn\/wp-content\/uploads\/2023\/12\/exceladvisor.org_.png\",\"contentUrl\":\"https:\/\/exceladvisor.org\/cn\/wp-content\/uploads\/2023\/12\/exceladvisor.org_.png\",\"width\":105,\"height\":36,\"caption\":\"Excel Advisor\"},\"image\":{\"@id\":\"https:\/\/exceladvisor.org\/cn\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u25b7 \u5982\u4f55\u5728VBA\u4e2d\u4f7f\u7528IF\u8bed\u53e5\u548cELSE\uff1f","description":"\u6761\u4ef6\u65e0\u5904\u4e0d\u5728\u3002\u5f53\u6d89\u53ca VBA \u7f16\u7801\u65f6\uff0c\u6761\u4ef6\u662f\u6700\u91cd\u8981\u7684\u4e8b\u60c5\u4e4b\u4e00\u3002\u5982\u679c\u4f60\u60f3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/exceladvisor.org\/cn\/\u5982\u679c-2\/","og_locale":"zh_CN","og_type":"article","og_title":"\u25b7 \u5982\u4f55\u5728VBA\u4e2d\u4f7f\u7528IF\u8bed\u53e5\u548cELSE\uff1f","og_description":"\u6761\u4ef6\u65e0\u5904\u4e0d\u5728\u3002\u5f53\u6d89\u53ca VBA \u7f16\u7801\u65f6\uff0c\u6761\u4ef6\u662f\u6700\u91cd\u8981\u7684\u4e8b\u60c5\u4e4b\u4e00\u3002\u5982\u679c\u4f60\u60f3","og_url":"https:\/\/exceladvisor.org\/cn\/\u5982\u679c-2\/","og_site_name":"Excel Advisor","article_modified_time":"2023-12-10T11:49:33+00:00","og_image":[{"url":"https:\/\/exceladvisor.org\/wp-content\/uploads\/2023\/08\/en-utilisant-le-code-dinstruction-VBA-IF-dans-Excel.png","type":"","width":"","height":""}],"twitter_card":"summary_large_image","twitter_misc":{"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/exceladvisor.org\/cn\/%e5%a6%82%e6%9e%9c-2\/","url":"https:\/\/exceladvisor.org\/cn\/%e5%a6%82%e6%9e%9c-2\/","name":"\u25b7 \u5982\u4f55\u5728VBA\u4e2d\u4f7f\u7528IF\u8bed\u53e5\u548cELSE\uff1f","isPartOf":{"@id":"https:\/\/exceladvisor.org\/cn\/#website"},"primaryImageOfPage":{"@id":"https:\/\/exceladvisor.org\/cn\/%e5%a6%82%e6%9e%9c-2\/#primaryimage"},"image":{"@id":"https:\/\/exceladvisor.org\/cn\/%e5%a6%82%e6%9e%9c-2\/#primaryimage"},"thumbnailUrl":"https:\/\/exceladvisor.org\/wp-content\/uploads\/2023\/08\/en-utilisant-le-code-dinstruction-VBA-IF-dans-Excel.png","datePublished":"2023-09-28T18:49:51+00:00","dateModified":"2023-12-10T11:49:33+00:00","description":"\u6761\u4ef6\u65e0\u5904\u4e0d\u5728\u3002\u5f53\u6d89\u53ca VBA \u7f16\u7801\u65f6\uff0c\u6761\u4ef6\u662f\u6700\u91cd\u8981\u7684\u4e8b\u60c5\u4e4b\u4e00\u3002\u5982\u679c\u4f60\u60f3","breadcrumb":{"@id":"https:\/\/exceladvisor.org\/cn\/%e5%a6%82%e6%9e%9c-2\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/exceladvisor.org\/cn\/%e5%a6%82%e6%9e%9c-2\/"]}]},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/exceladvisor.org\/cn\/%e5%a6%82%e6%9e%9c-2\/#primaryimage","url":"https:\/\/exceladvisor.org\/wp-content\/uploads\/2023\/08\/en-utilisant-le-code-dinstruction-VBA-IF-dans-Excel.png","contentUrl":"https:\/\/exceladvisor.org\/wp-content\/uploads\/2023\/08\/en-utilisant-le-code-dinstruction-VBA-IF-dans-Excel.png"},{"@type":"BreadcrumbList","@id":"https:\/\/exceladvisor.org\/cn\/%e5%a6%82%e6%9e%9c-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u5bb6","item":"https:\/\/exceladvisor.org\/cn\/"},{"@type":"ListItem","position":2,"name":"\u5982\u4f55\u5728vba\u4e2d\u4f7f\u7528if\u8bed\u53e5\u548celse\uff1f"}]},{"@type":"WebSite","@id":"https:\/\/exceladvisor.org\/cn\/#website","url":"https:\/\/exceladvisor.org\/cn\/","name":"Excel Advisor","description":"\u60a8\u7684\u6570\u636e\u7edf\u6cbb\u7ec8\u6781\u6307\u5357","publisher":{"@id":"https:\/\/exceladvisor.org\/cn\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/exceladvisor.org\/cn\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"zh-Hans"},{"@type":"Organization","@id":"https:\/\/exceladvisor.org\/cn\/#organization","name":"Excel Advisor","url":"https:\/\/exceladvisor.org\/cn\/","logo":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/exceladvisor.org\/cn\/#\/schema\/logo\/image\/","url":"https:\/\/exceladvisor.org\/cn\/wp-content\/uploads\/2023\/12\/exceladvisor.org_.png","contentUrl":"https:\/\/exceladvisor.org\/cn\/wp-content\/uploads\/2023\/12\/exceladvisor.org_.png","width":105,"height":36,"caption":"Excel Advisor"},"image":{"@id":"https:\/\/exceladvisor.org\/cn\/#\/schema\/logo\/image\/"}}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/exceladvisor.org\/cn\/wp-json\/wp\/v2\/pages\/677","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/exceladvisor.org\/cn\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/exceladvisor.org\/cn\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/exceladvisor.org\/cn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/exceladvisor.org\/cn\/wp-json\/wp\/v2\/comments?post=677"}],"version-history":[{"count":1,"href":"https:\/\/exceladvisor.org\/cn\/wp-json\/wp\/v2\/pages\/677\/revisions"}],"predecessor-version":[{"id":1242,"href":"https:\/\/exceladvisor.org\/cn\/wp-json\/wp\/v2\/pages\/677\/revisions\/1242"}],"wp:attachment":[{"href":"https:\/\/exceladvisor.org\/cn\/wp-json\/wp\/v2\/media?parent=677"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}