{"id":14722,"date":"2018-04-09T15:51:18","date_gmt":"2018-04-09T15:51:18","guid":{"rendered":"http:\/\/learnexcelmacro.com\/wp\/?p=14722"},"modified":"2022-08-17T19:17:44","modified_gmt":"2022-08-17T19:17:44","slug":"recording-macro-relative-references-and-absolute-method","status":"publish","type":"post","link":"https:\/\/vmlogger.com\/excel\/2018\/04\/recording-macro-relative-references-and-absolute-method\/","title":{"rendered":"Recording Macro – Relative References and Absolute Method"},"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 article is intended for Excel VBA beginners. Here in this article, I am going to explain to you the use of the Use Relative Reference<\/em> option in Excel VBA while recording your macro. <\/p>\n My focus in this article would be on explaining you these two different methods which you can use while recording – Under the Developer tab in your Excel workbook, you can see there is a toggle option available below the record macro button as shown in the below picture. Relative Reference in Excel recording<\/p><\/div>\n As I mentioned this is a toggle button – if this button is highlighted in a different color – that means it is ON else OFF. <\/p>\n Refer to the below picture, here this button looks highlighted, which means, if you record your macro now, It will be recorded with Relative reference.<\/p>\n Relative Reference On<\/p><\/div>\n When Relative Reference is OFF – it is also called Recording in Absolute Mode<\/em> else it is called Recording with Relative Reference<\/em>. From this, it is clear that there is not a separate button available for Recording in the absolute method.<\/p>\n Now, let’s have a close look at the code which is recorded in the Absolute method as shown below <\/p>\n Macro Recording – Absolute Method -Off<\/p><\/div>\n In the above-recorded macro you can see that in every cell where values are entered, they are all having the exact address. For example – Range(“C3”), Range(“D3”) etc.<\/em><\/p>\n Same macro, now I am going to record using the Use Relative Reference<\/em> button ON.<\/p>\n From the above-recorded code, you can see that all the cells or range addresses are recorded as relative and not absolute. When you are recording your macro using this method, you will see every cell address is referred to using Offset Function. To know more about the Offset function read this article.<\/p>\n From the above two codes, you can see that the recorded code using the first method (Absolute method) is using the exact or absolute address of each cell or cell range whereas in the second method – using Relative Reference turned on, the recorded code is not using any exact address. Cells are referred to relatively using the Offset function.\n<\/p><\/div>\n [\/et_pb_text][et_pb_blurb title=”You may also like reading these:” use_icon=”on” font_icon=”||fa||900″ _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 article is intended for Excel VBA beginners. Here in this article, I am going to explain to you the use of the Use Relative Reference option in Excel VBA while recording your macro. My focus in this article would be on explaining you these two different methods which you can use while […]<\/p>\n","protected":false},"author":45,"featured_media":14725,"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":[1246],"tags":[],"class_list":["post-14722","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-macro"],"yoast_head":"\n
\n1. <\/em>Use Relative Reference Method
\n2. <\/em>Absolute Method\n<\/p>\n
\nWhat is Excel Macro ?<\/a>
\nHow to Record \/ Run Excel Macro ?<\/a>\n<\/div>\nWhat is Relative Reference Option in Macro Recording<\/h1>\n
\nTo know how to enable Developer tab in your Excel Workbook, click here<\/a><\/p>\n<\/a>
<\/a>
Recording Macro with Use Relative Reference – Off<\/em><\/h2>\n
\n
\n\nSub AbsoluteMethod()\n'\n' AbsoluteMethod Macro\n' This macro is recorded with -\n' Use Relative Reference --> OFF --> Absolute Method\n'\n\n'\n Range(\"C3\").Select\n ActiveCell.FormulaR1C1 = \"Name\"\n Range(\"D3\").Select\n ActiveCell.FormulaR1C1 = \"Vishwamitra\"\n Range(\"C4\").Select\n ActiveCell.FormulaR1C1 = \"Age\"\n Range(\"D4\").Select\n ActiveCell.FormulaR1C1 = \"30 Years\"\n Range(\"C5\").Select\n ActiveCell.FormulaR1C1 = \"Address\"\n Range(\"D5\").Select\n ActiveCell.FormulaR1C1 = \"Amsterdam\"\n Range(\"C6\").Select\n ActiveCell.FormulaR1C1 = \"Email Address\"\n Range(\"D6\").Select\n ActiveCell.FormulaR1C1 = \"info@learnexcelmacro.com\"\n Range(\"D7\").Select\nEnd Sub\n\n<\/code>\n\n<\/pre>\n
Recording Macro with Use Relative Reference – ON<\/h2>\n
\n
\nSub RelativeReferenceMethod()\n'\n' RelativeReferenceMethod Macro\n' This Macro is recorded with -\n' Use Relative Reference --> ON --> Relative Reference Method\n'\n\n'\n ActiveCell.Offset(-4, -1).Range(\"A1\").Select\n ActiveCell.FormulaR1C1 = \"Name\"\n ActiveCell.Offset(0, 1).Range(\"A1\").Select\n ActiveCell.FormulaR1C1 = \"Vishwamitra\"\n ActiveCell.Offset(1, -1).Range(\"A1\").Select\n ActiveCell.FormulaR1C1 = \"Age\"\n ActiveCell.Offset(0, 1).Range(\"A1\").Select\n ActiveCell.FormulaR1C1 = \"30 Years\"\n ActiveCell.Offset(1, -1).Range(\"A1\").Select\n ActiveCell.FormulaR1C1 = \"Address\"\n ActiveCell.Offset(0, 1).Range(\"A1\").Select\n ActiveCell.FormulaR1C1 = \"Amsterdam\"\n ActiveCell.Offset(1, -1).Range(\"A1\").Select\n ActiveCell.FormulaR1C1 = \"Email Address\"\n ActiveCell.Offset(0, 1).Range(\"A1\").Select\n ActiveCell.FormulaR1C1 = \"info@learnexcelmacro.com\"\n ActiveCell.Offset(1, 0).Range(\"A1\").Select\nEnd Sub\n\n<\/code>\n<\/pre>\n
Conclusion<\/h2>\n
\n
\n<\/a><\/li>\n
\n<\/a><\/li>\n<\/ol>\n