

{"id":96527,"date":"2021-06-21T09:00:31","date_gmt":"2021-06-21T03:30:31","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=96527"},"modified":"2021-06-06T14:18:46","modified_gmt":"2021-06-06T08:48:46","slug":"vba-comparison-operators","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/vba-comparison-operators\/","title":{"rendered":"VBA Comparison Operators"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">Comparison operators are the operators that are used to compare values. Some of the comparison operators are equal to (=), less than (&lt;), greater than(&gt;) and not equal to(&lt;&gt;).<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The user mostly uses comparison operators to compare the values for the purpose of validation. Comparison operators come in handy in situations such as where you want to compare the total amount you invested vs the amount you had in your hand.\u00a0<\/span><\/p>\n<h3>VBA Comparison Operators<\/h3>\n<table>\n<tbody>\n<tr>\n<td><b>Function<\/b><\/td>\n<td><b>Operator<\/b><\/td>\n<td><b>Description<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">&lt;<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Less than<\/span><\/td>\n<td><span style=\"font-weight: 400;\">This operator returns true if the LHS value is lesser than the RHS value or else it returns false.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">&gt;<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Greater than<\/span><\/td>\n<td><span style=\"font-weight: 400;\">This operator returns true if the LHS value is greater than the RHS value or else it returns false.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">&lt;=<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Lesser than or Equal To<\/span><\/td>\n<td><span style=\"font-weight: 400;\">This operator returns true if the LHS value is lesser than or equal to the RHS value or else it returns false.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">&gt;=<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Greater than or Equal To<\/span><\/td>\n<td><span style=\"font-weight: 400;\">This operator returns true if the LHS value is greater than or equal to the RHS value or else it returns false.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">=<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Equal To<\/span><\/td>\n<td><span style=\"font-weight: 400;\">This operator returns true if the two values are equal or else it returns false.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">&lt;&gt;<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Not Equal To<\/span><\/td>\n<td><span style=\"font-weight: 400;\">This operator returns true if the two values are not equal to each other or else it returns false.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Example of VBA Comparison Operators<\/h3>\n<p><span style=\"font-weight: 400;\">To perform comparison operations, follow the steps:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">1: Open an excel workbook and save it as an excel macro-enabled workbook.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">2: <\/span><b>\u00a0<\/b><span style=\"font-weight: 400;\">Add a button using macros.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In order to create a macro,\u00a0<\/span><\/p>\n<ul>\n<li><span style=\"font-weight: 400;\">Go to the developer tab and click on insert from the ribbon.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Choose the command button.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Assign a macro by providing a name and click on the new button\u00a0<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">3: Finally, press ok.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">4: Once the code window appears, type the code.<\/span><\/p>\n<h4>1. Equal To Operator<\/h4>\n<p><strong>Example of Equal to Operator in VBA<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Sub Button1_Click()\r\n\u00a0\u00a0\u00a0\u00a0Dim a As Integer, b As Integer\r\n\u00a0\u00a0\u00a0\u00a0a = 5\r\n\u00a0\u00a0\u00a0\u00a0b = 5\r\n\u00a0\u00a0\u00a0\u00a0If a = b Then\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0MsgBox \"True\", vbOKOnly, \"Comparison Operation\"\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Else\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0MsgBox \"False\", vbOKOnly, \"Comparison Operation\"\r\n\u00a0\u00a0\u00a0\u00a0End If\r\nEnd Sub<\/pre>\n<p><b>Code Explanation:<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Here, Sub Button1_Click() is the sub procedure.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u2018a\u2019 and \u2018b\u2019 are integer data type variables. The comparison operator i.e., equal to (=) here checks whether the a and b values are equal. If the values are equal, it returns true.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The result will appear in a message box with the \u2018Comparison Operation\u2019 title.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The user writes the code in the VBA editor.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">5: Click on save button or press ctrl+s.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">6: Close the vba code editor window.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Your GUI appears as follows:<\/span><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/gui-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-96788\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/gui-1.png\" alt=\"Comparison Operators in VBA GUI\" width=\"826\" height=\"370\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/gui-1.png 826w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/gui-1-300x134.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/gui-1-150x67.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/gui-1-768x344.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/gui-1-720x323.png 720w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/gui-1-520x233.png 520w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/gui-1-320x143.png 320w\" sizes=\"auto, (max-width: 826px) 100vw, 826px\" \/><\/a><\/p>\n<p><span style=\"font-weight: 400;\">Once you click on the button, you will get the output:<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/equal-to-result.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-96790\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/equal-to-result.png\" alt=\"equal to Operator in VBA\" width=\"1608\" height=\"496\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/equal-to-result.png 1608w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/equal-to-result-300x93.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/equal-to-result-1024x316.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/equal-to-result-150x46.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/equal-to-result-768x237.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/equal-to-result-1536x474.png 1536w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/equal-to-result-720x222.png 720w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/equal-to-result-520x160.png 520w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/equal-to-result-320x99.png 320w\" sizes=\"auto, (max-width: 1608px) 100vw, 1608px\" \/><\/a><\/p>\n<h4>2. Not Equal To Operator in VBA<\/h4>\n<p><b>Example of VBA Not Equal To Operator<\/b><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Sub Button1_Click()\r\n\u00a0\u00a0\u00a0\u00a0Dim a As Integer, b As Integer\r\n\u00a0\u00a0\u00a0\u00a0a = 5\r\n\u00a0\u00a0\u00a0\u00a0b = 5\r\n\u00a0\u00a0\u00a0\u00a0If a &lt;&gt; b Then\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0MsgBox \"True\", vbOKOnly, \"Comparison Operation\"\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Else\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0MsgBox \"False\", vbOKOnly, \"Comparison Operation\"\r\n\u00a0\u00a0\u00a0\u00a0End If\r\nEnd Sub<\/pre>\n<p><b>Code Explanation:<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Here, Sub Button1_Click() is the sub procedure.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u2018a\u2019 and \u2018b\u2019 are integer data type variables. The comparison operator i.e., not equal to (&lt;&gt;) here checks whether the a and b values are not equal. If the values are equal, it returns false.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The result will appear in a message box with the \u2018Comparison Operation\u2019 title. <\/span><span style=\"font-weight: 400;\">Your GUI appears<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Once you click on the button, the following output appears:<\/span><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/not-eq-to-result.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-96791\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/not-eq-to-result.png\" alt=\"Not Equal to Operator in VBA\" width=\"1271\" height=\"488\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/not-eq-to-result.png 1271w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/not-eq-to-result-300x115.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/not-eq-to-result-1024x393.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/not-eq-to-result-150x58.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/not-eq-to-result-768x295.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/not-eq-to-result-720x276.png 720w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/not-eq-to-result-520x200.png 520w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/not-eq-to-result-320x123.png 320w\" sizes=\"auto, (max-width: 1271px) 100vw, 1271px\" \/><\/a><\/p>\n<h4>3. Less Than Operator in VBA<\/h4>\n<p><b>Example of VBA Less Than Operator<\/b><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Sub Comparison_Click()\r\n\u00a0\u00a0\u00a0\u00a0Dim a As Integer, b As Integer\r\n\u00a0\u00a0\u00a0\u00a0a = 5\r\n\u00a0\u00a0\u00a0\u00a0b = 5\r\n\u00a0\u00a0\u00a0\u00a0If a &lt; b Then\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0MsgBox \"The value stored in 'a' variable is less than 'b' variable\", vbOKOnly, \"Comparison Operation\"\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Else\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0MsgBox \"The value stored in 'a' variable is not less than 'b' variable\", vbOKOnly, \"Comparison Operation\"\r\n\u00a0\u00a0\u00a0\u00a0End If\r\nEnd Sub<\/pre>\n<p><b>Code Explanation<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Here, Sub Comparison_Click() is the sub procedure.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u2018a\u2019 and \u2018b\u2019 are integer data type variables. The comparison operator i.e., less than(&lt;) operator here checks whether the \u2018a\u2019 value is less than the \u2018b\u2019 value. If this condition satisfies, the result appears as \u2018The value stored in &#8216;a&#8217; variable is less than &#8216;b&#8217; variable\u2019 or else it returns as \u2018&#8221;The value stored in &#8216;a&#8217; variable is not less than &#8216;b&#8217; variable\u2019.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The result will appear in a message box with the \u2018Comparison Operation\u2019 title. <\/span><span style=\"font-weight: 400;\">Your GUI appears.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">When you click on the button, the following output appears:<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/not-less-than-op.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-96796\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/not-less-than-op.png\" alt=\"Less than Operator in VBA\" width=\"1920\" height=\"992\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/not-less-than-op.png 1920w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/not-less-than-op-300x155.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/not-less-than-op-1024x529.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/not-less-than-op-150x78.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/not-less-than-op-768x397.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/not-less-than-op-1536x794.png 1536w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/not-less-than-op-720x372.png 720w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/not-less-than-op-520x269.png 520w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/not-less-than-op-320x165.png 320w\" sizes=\"auto, (max-width: 1920px) 100vw, 1920px\" \/><\/a><\/p>\n<h4>5. Greater Than Operator in VBA<\/h4>\n<p><b>Example of VBA Greater Than Operator<\/b><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Sub Comparison_Click()\r\n\u00a0\u00a0\u00a0\u00a0Dim a As Integer, b As Integer\r\n\u00a0\u00a0\u00a0\u00a0a = 5\r\n\u00a0\u00a0\u00a0\u00a0b = 5\r\n\u00a0\u00a0\u00a0\u00a0If a &gt; b Then\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0MsgBox \"The value stored in 'a' variable is greater than 'b' variable\", vbOKOnly, \"Comparison Operation\"\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Else\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0MsgBox \"The value stored in 'a' variable is not greater than 'b' variable\", vbOKOnly, \"Comparison Operation\"\r\n\u00a0\u00a0\u00a0\u00a0End If\r\nEnd Sub<\/pre>\n<p><b>Code Explanation:<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Here, Sub Comparison_Click() is the sub procedure.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u2018a\u2019 and \u2018b\u2019 are integer data type variables. The comparison operator i.e., greater than(&gt;) operator here checks whether the \u2018a\u2019 value is greater than the \u2018b\u2019 value. If this condition satisfies, the result appears as \u2018The value stored in &#8216;a&#8217; variable is greater than \u2018b\u2019 variable\u2019 or else it returns as \u2018&#8221;The value stored in &#8216;a&#8217; variable is not greater than &#8216;b&#8217; variable\u2019.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The result will appear in a message box with the \u2018Comparison Operation\u2019 title. <\/span><span style=\"font-weight: 400;\">Your GUI appears:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">When you click on the button, the following output appears:<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/Not-great-than-op.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-96795\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/Not-great-than-op.png\" alt=\"Greater than Operator in VBA\" width=\"1868\" height=\"846\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/Not-great-than-op.png 1868w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/Not-great-than-op-300x136.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/Not-great-than-op-1024x464.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/Not-great-than-op-150x68.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/Not-great-than-op-768x348.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/Not-great-than-op-1536x696.png 1536w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/Not-great-than-op-720x326.png 720w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/Not-great-than-op-520x236.png 520w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/Not-great-than-op-320x145.png 320w\" sizes=\"auto, (max-width: 1868px) 100vw, 1868px\" \/><\/a><\/p>\n<h4>6. Lesser than or Equal To Operator in VBA<\/h4>\n<p><b>Example of Lesser than or Equal To Operator in VBA<\/b><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Sub Comparison_Click()\r\n\u00a0\u00a0\u00a0\u00a0Dim a As Integer, b As Integer\r\n\u00a0\u00a0\u00a0\u00a0a = 5\r\n\u00a0\u00a0\u00a0\u00a0b = 5\r\n\u00a0\u00a0\u00a0\u00a0If a &lt;= b Then\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0 MsgBox \"The value stored in 'a' variable is lesser than or equal to 'b' variable\", vbOKOnly, \"Comparison Operation\"\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Else\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0MsgBox \"The value stored in 'a' variable is not lesser than or equal to 'b' variable\", vbOKOnly, \"Comparison Operation\"\r\n\u00a0\u00a0\u00a0\u00a0End If\r\nEnd Sub<\/pre>\n<p>&nbsp;<\/p>\n<p><b>Code Explanation:<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Here, Sub Comparison_Click() is the sub procedure.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u2018a\u2019 and \u2018b\u2019 are integer data type variables. The comparison operator i.e., Lesser than or Equal To than(&lt;=) operator here checks whether the \u2018a\u2019 value is lesser than or Equal To the \u2018b\u2019 value. If this condition satisfies, the result appears as \u2018The value stored in &#8216;a&#8217; variable is lesser than or Equal To &#8216;b&#8217; variable\u2019 or else it returns as \u2018The value stored in &#8216;a&#8217; variable is not lesser than or Equal To &#8216;b&#8217; variable\u2019.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The result will appear in a message box with the \u2018Comparison Operation\u2019 title. <\/span><span style=\"font-weight: 400;\">Your GUI appears.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">When you click on the button, the following output appears:<\/span><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/lesser-than-or-equal-to-op.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-96794\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/lesser-than-or-equal-to-op.png\" alt=\"lesser than or equal to operator in VBA\" width=\"1868\" height=\"851\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/lesser-than-or-equal-to-op.png 1868w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/lesser-than-or-equal-to-op-300x137.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/lesser-than-or-equal-to-op-1024x467.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/lesser-than-or-equal-to-op-150x68.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/lesser-than-or-equal-to-op-768x350.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/lesser-than-or-equal-to-op-1536x700.png 1536w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/lesser-than-or-equal-to-op-720x328.png 720w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/lesser-than-or-equal-to-op-520x237.png 520w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/lesser-than-or-equal-to-op-320x146.png 320w\" sizes=\"auto, (max-width: 1868px) 100vw, 1868px\" \/><\/a><\/p>\n<h4>7. Greater than or Equal To Operator in VBA<\/h4>\n<p><b>Example of Greater than or Equal to Operator in VBA<\/b><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Sub Comparison_Click()\r\n\u00a0\u00a0\u00a0\u00a0Dim a As Integer, b As Integer\r\n\u00a0\u00a0\u00a0\u00a0a = 5\r\n\u00a0\u00a0\u00a0\u00a0b = 5\r\n\u00a0\u00a0\u00a0\u00a0If a &gt;= b Then\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0 MsgBox \"The value stored in 'a' variable is greater than or equal to 'b' variable\", vbOKOnly, \"Comparison Operation\"\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Else\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0MsgBox \"The value stored in 'a' variable is not greater than or equal to 'b' variable\", vbOKOnly, \"Comparison Operation\"\r\n\u00a0\u00a0\u00a0\u00a0End If\r\nEnd Sub<\/pre>\n<p><b>Code Explanation:<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Here, Sub Comparison_Click() is the sub procedure.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u2018a\u2019 and \u2018b\u2019 are integer data type variables. The comparison operator i.e., Greater than or Equal To than(&gt;=) operator here checks whether the \u2018a\u2019 value is Greater than or Equal To the \u2018b\u2019 value. If this condition satisfies, the result appears as \u2018The value stored in &#8216;a&#8217; variable is greater than or Equal To &#8216;b&#8217; variable\u2019 or else it returns as \u2018The value stored in &#8216;a&#8217; variable is not greater than or Equal To &#8216;b&#8217; variable\u2019.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The result will appear in a message box with the \u2018Comparison Operation\u2019 title. <\/span><span style=\"font-weight: 400;\">Your GUI appears.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">When you click on the button, the following output appears:<\/span><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/greater-than-output.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-96793\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/greater-than-output.png\" alt=\"greater than or Equal to operator in VBA\" width=\"1862\" height=\"838\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/greater-than-output.png 1862w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/greater-than-output-300x135.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/greater-than-output-1024x461.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/greater-than-output-150x68.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/greater-than-output-768x346.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/greater-than-output-1536x691.png 1536w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/greater-than-output-720x324.png 720w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/greater-than-output-520x234.png 520w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/greater-than-output-320x144.png 320w\" sizes=\"auto, (max-width: 1862px) 100vw, 1862px\" \/><\/a><\/p>\n<h3>Summary<\/h3>\n<p><span style=\"font-weight: 400;\">1. The comparison operator helps the user to compare the data values.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">2. They are widely helpful in data validation purposes.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">3. Some of the comparison operators are <\/span><span style=\"font-weight: 400;\">equal to (=), less than (&lt;), greater than(&gt;) and not equal to(&lt;&gt;).<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Comparison operators are the operators that are used to compare values. Some of the comparison operators are equal to (=), less than (&lt;), greater than(&gt;) and not equal to(&lt;&gt;). The user mostly uses comparison&#46;&#46;&#46;<\/p>\n","protected":false},"author":7,"featured_media":96786,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24129],"tags":[24537,24540,24538,24539,24541],"class_list":["post-96527","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ms-excel","tag-vba-comparison-operators","tag-vba-equal-to-operator","tag-vba-greater-than-operator","tag-vba-less-than-operator","tag-vba-not-equal-to-operator"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>VBA Comparison Operators - DataFlair<\/title>\n<meta name=\"description\" content=\"Excel VBA Comparison Operators include Equal to, Less than, Greater than, Not equal to , Less than or equal to, Greater than or equal to.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/vba-comparison-operators\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"VBA Comparison Operators - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Excel VBA Comparison Operators include Equal to, Less than, Greater than, Not equal to , Less than or equal to, Greater than or equal to.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/vba-comparison-operators\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-06-21T03:30:31+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/VBA-Comparison-Operators.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"VBA Comparison Operators - DataFlair","description":"Excel VBA Comparison Operators include Equal to, Less than, Greater than, Not equal to , Less than or equal to, Greater than or equal to.","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:\/\/data-flair.training\/blogs\/vba-comparison-operators\/","og_locale":"en_US","og_type":"article","og_title":"VBA Comparison Operators - DataFlair","og_description":"Excel VBA Comparison Operators include Equal to, Less than, Greater than, Not equal to , Less than or equal to, Greater than or equal to.","og_url":"https:\/\/data-flair.training\/blogs\/vba-comparison-operators\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2021-06-21T03:30:31+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/VBA-Comparison-Operators.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/vba-comparison-operators\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/vba-comparison-operators\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/beb0cab24b7aa54423a3b50e669a9dcd"},"headline":"VBA Comparison Operators","datePublished":"2021-06-21T03:30:31+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/vba-comparison-operators\/"},"wordCount":1021,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/vba-comparison-operators\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/VBA-Comparison-Operators.jpg","keywords":["VBA Comparison Operators","VBA Equal to Operator","VBA Greater Than Operator","VBA Less Than Operator","VBA Not Equal To Operator"],"articleSection":["MS Excel Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/vba-comparison-operators\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/vba-comparison-operators\/","url":"https:\/\/data-flair.training\/blogs\/vba-comparison-operators\/","name":"VBA Comparison Operators - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/vba-comparison-operators\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/vba-comparison-operators\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/VBA-Comparison-Operators.jpg","datePublished":"2021-06-21T03:30:31+00:00","description":"Excel VBA Comparison Operators include Equal to, Less than, Greater than, Not equal to , Less than or equal to, Greater than or equal to.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/vba-comparison-operators\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/vba-comparison-operators\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/vba-comparison-operators\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/VBA-Comparison-Operators.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/VBA-Comparison-Operators.jpg","width":1200,"height":628,"caption":"VBA Comparison Operators"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/vba-comparison-operators\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"MS Excel Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/ms-excel\/"},{"@type":"ListItem","position":3,"name":"VBA Comparison Operators"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/beb0cab24b7aa54423a3b50e669a9dcd","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/c322416204232f4dd97ef3901b0a499a5d34d7ba7fe333f4bfe53a907873d293?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/c322416204232f4dd97ef3901b0a499a5d34d7ba7fe333f4bfe53a907873d293?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c322416204232f4dd97ef3901b0a499a5d34d7ba7fe333f4bfe53a907873d293?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team specializes in creating clear, actionable content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Backed by industry expertise, we make learning easy and career-oriented for beginners and pros alike.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam3\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/96527","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=96527"}],"version-history":[{"count":4,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/96527\/revisions"}],"predecessor-version":[{"id":96797,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/96527\/revisions\/96797"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/96786"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=96527"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=96527"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=96527"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}