{"id":14695,"date":"2018-04-02T17:36:47","date_gmt":"2018-04-02T17:36:47","guid":{"rendered":"http:\/\/learnexcelmacro.com\/wp\/?p=14695"},"modified":"2022-08-17T19:18:11","modified_gmt":"2022-08-17T19:18:11","slug":"how-to-comment-a-line-or-group-of-lines-in-excel-vba","status":"publish","type":"post","link":"https:\/\/vmlogger.com\/excel\/2018\/04\/how-to-comment-a-line-or-group-of-lines-in-excel-vba\/","title":{"rendered":"3 Methods to Comment or Uncomment in Excel VBA"},"content":{"rendered":"
[et_pb_section fb_built=”1″ admin_label=”section” _builder_version=”4.16″ da_disable_devices=”off|off|off” global_colors_info=”{}” da_is_popup=”off” da_exit_intent=”off” da_has_close=”on” da_alt_close=”off” da_dark_close=”off” da_not_modal=”on” da_is_singular=”off” da_with_loader=”off” da_has_shadow=”on”][et_pb_row admin_label=”row” _builder_version=”4.16″ background_size=”initial” background_position=”top_left” background_repeat=”repeat” global_colors_info=”{}”][et_pb_column type=”4_4″ _builder_version=”4.16″ custom_padding=”|||” global_colors_info=”{}” custom_padding__hover=”|||”][et_pb_text _builder_version=”4.17.6″ _module_preset=”default” global_colors_info=”{}”]Dear Friends,<\/p>\n
This is a very simple yet useful article, especially for beginners. Sometimes even intermediate-level users also do not know about all these options to comment on a line or group of lines in Excel VBA.<\/p>\n
Like every other programming language, VBA too has an option to comment on a line or group of lines in your code. Commenting a line or group of lines in any programming language means – to instruct the execution control or compiler to skip those lines from compilation or execution. <\/em><\/p>\n Before I tell you how to comment on a line in Excel VBA, let me explain to you – the use of it<\/p>\n As mentioned above these comments is something that is not compiled or executed, a programmer can write anything in any simple human language to give a brief description of a function, a variable, a statement, etc. It is not MANDATORY but a good programming practice to provide proper comments so that any other programmer can easily understand the code easily.<\/p>\n<\/div>\n Basically, there are 3 ways to do so. <\/p>\n This is one of the simplest methods to comment on a single line in VBA programming. To Comment a line in VBA<\/p><\/div>\n A single quote can be put somewhere in the middle of a line as well. In such case, rest of the text after the single quote (‘)<\/span> will be treated as comment. Comment Line in VBA<\/p><\/div><\/p>\n This is also a simple one but I do not prefer this. You can see the reason below in the note section. <\/p>\n To comment on any line in VBA you can start that line with the keyword Rem Keyword to comment a line<\/p><\/div>\n Following are the limitation using this Rem keyword I think the above two reasons are more than enough for me not to like it :). <\/p>\n This is the same method as the first one, but here you do not need to type a Single quote by yourself, rather you can follow the below steps: Toggle between comment and un-comment<\/p><\/div>\n Using this method you also get an option to press the “Uncomment” button as well as shown in the above gif video.<\/p><\/div>\n Unfortunately in VBA, there is no shortcut key to do so. But don’t worry, method 3 is very useful in this case. Step 1:<\/em> Select all the lines (block) Comment Uncomment VBA Methods<\/p><\/div>\n Step 1:<\/em> Select all the commented lines (block) Comment Uncomment VBA Methods<\/p><\/div>\n Follow the below steps: VBE – View Edit Option<\/p><\/div> Comment-uncomment-button<\/p><\/div>[\/et_pb_text][et_pb_blurb title=”Few more interesting tips:” use_icon=”on” font_icon=”||fa||400″ _builder_version=”4.17.6″ _module_preset=”0249c68e-4de8-4f44-84ff-a9b1850785b6″ hover_enabled=”0″ global_colors_info=”{}” sticky_enabled=”0″]<\/p>\n [\/et_pb_blurb][\/et_pb_column][\/et_pb_row][\/et_pb_section]<\/p>\n<\/span>","protected":false},"excerpt":{"rendered":" Dear Friends, This is a very simple yet useful article, especially for beginners. Sometimes even intermediate-level users also do not know about all these options to comment on a line or group of lines in Excel VBA. Like every other programming language, VBA too has an option to comment on a line or group of […]<\/p>\n","protected":false},"author":45,"featured_media":242607,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"on","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[1676,5204],"tags":[],"class_list":["post-14695","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-excel-tips","category-vba-programming"],"yoast_head":"\n
\nFor those who does not know – what is comment in a Programming:<\/em><\/span><\/p>\nWhat is the use of comments in Excel VBA Programming<\/h2>\n
\nThis makes the programmer’s life easier from a maintenance perspective. By reading those brief descriptions of the code, any programmer can have a basic idea of what that function or statement or variable, etc. does.<\/p>\nHow to comment a single line in VBA code <\/h1>\n
Method 1: Using Single Quote (‘) <\/h2>\n
\nTo comment on a line, you can simply type a single quote (‘)<\/span> at the beginning of that line. The whole line will turn into green text. That’s all!
\nNow that line would neither be compiled nor executed. <\/p>\nNote:<\/h3>\n
\nRefer to the below image
\n<\/a>
Method 2: Using
REM<\/code> Keyword in Excel VBA <\/h2>\n
REM <\/code> So in this method, instead of a single quote (apostrophe) you can type the Rem keyword. <\/p>\n
Note:<\/h3>\n
\n1.<\/em> There should be at least one space between the start of your comment and the Rem keyword.
\n2.<\/em> Like a single quote, the Rem keyword can not be used in the middle of a line to comment rest of the line. Rem keyword must always be the first word to start with.<\/p>\nMethod 3: VBE built-in Option – Comment\/Uncomment Block <\/h2>\n
\n1.<\/em> Place your mouse cursor anywhere on the line on which you want to comment
\n2.<\/em> Press on “Comment” button as shown in below video<\/p>\nImportant:<\/h3>\n
How to comment or un-comment multiple lines together <\/h1>\n
\nYou can use the same buttons Comment Block and Un-comment Block <\/em><\/span> to do this.
\nSimply select all the lines you want to comment on or uncomment it and press the relevant button as shown below:<\/p>\n1# How to comment group of lines (Block) in VBA <\/h2>\n
\nStep 2: <\/em>Press the Comment Block<\/span> as shown in above picture<\/p>\n2# How to Un-comment group of lines (Block) in VBA <\/h2>\n
\nStep 2: <\/em>Press the Uncomment Block<\/span> as shown in above picture<\/p>\nWhat if Comment Block and Uncomment Block Button not visible<\/h3>\n
\nStep 1:<\/em> Go to View –> Toolbars –> Edit<\/p>\n<\/a>
\nStep 2: <\/em>Check the Edit option. You will see the Edit toolbar where you can find these two options along with others.<\/p>\n<\/a>
\n