The Wayback Machine - https://web.archive.org/web/20250212162730/https://www.geeksforgeeks.org/absolute-references-in-excel-macros/
Open In App

Absolute References in Excel Macros

Last Updated: 06 Dec, 2023
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Share
Report
News Follow

Excel Macros are incredibly powerful tools that provide the capability to automate repetitive tasks, streamline processes, and save time. When building macros, it’s common to use cell references for performing calculations or actions. In some situations, it’s important to ensure that these references remain fixed, no matter where the macro is applied or copied. Here the absolute reference plays an important role.

We have two options to refer a cell in Excel VBA Absolute references and Relative references.  Default Excel records macro in Absolute mode.

Both absolute references and relative references can be used while recording Excel macros. Regardless of the active cell, a macro recorded using absolute references places the recorded steps exactly in the cells where it was recorded. However, a macro that has been recorded with relative references can carry out the activities at several locations on the worksheet.

In this article, we will learn about absolute references in Excel VBA. We record a macro to type some text in cells B2:B4.  Macro always types the text in the cells B2:B4, irrespective of the active cell.

Ensuring Absolute References

We must make sure that the macro is recorded starting from the cell where the steps must begin in order to record a macro with absolute references.

Implementation

Follow the below steps to implement Absolute references in Excel macros:

Step 1: Open Excel and Select Cell “A1”

Note: The macro will place whatever you recorded on the same worksheet in the same location if you do not create a new worksheet before running it. You do not want this. Every report needs to be on a different worksheet.

Recording a Macro

The Record Macro command, located on the ribbon under the VIEW tab Macros, allows you to begin recording the macro. 

On the left side of the Excel taskbar, there is a button that says “Start Recording Macro” which you can also use.

Step 2: Go to the “Developer” Tab >> Click “Record Macro”

Record Macro button

Give the macro a name that will help others recognize it as a report for a certain project.

Step 3: Enter the Macro name “absolute Reference” and Press “OK”

Record Macro Dialogue Box

Your macro begins to record

Step 4: Type “Australia” in cell B2

Step 5: Type “Brazil” in cell B3

Step 6: Type “Mexico” in cell B4

Stop recording the macro

Either use the Stop Recording command located on the ribbon under the VIEW tab Macros or click the Stop Recording Macro button located on the left side of the Excel taskbar to stop recording the macro.

Click on cell B5. This makes sure that the macro always records your steps in B5.

Step 7: Select cell B5 and Press “Stop Recording”

Stop Recording

VBA Code (Recorded)

Sub absoluteReference()

    Range(“B2”).Select

    ActiveCell.FormulaR1C1 = “Australia”

    Range(“B3”).Select

    ActiveCell.FormulaR1C1 = “Brazil”

    Range(“B4”).Select

    ActiveCell.FormulaR1C1 = “Mexico”

    Range(“B5”).Select

End Sub

Step 8: We can just delete the contents in cells B2:B4

Step 9: Go to View >> Macros >> View Macros – to pop-up Macro dialogue box [keyboard shortcut – Alt+F8]

View Macros

Running a Macro

Simply by running the macro, you may create any number of reports in a matter of seconds.

Step 10: On the Ribbon, select the VIEW button and Click Macros 

Step 11: Select a Macro from the list (e.g. absolute Reference) and Press “Run”

Macro Dialogue Box

Output

Output

Importance of Absolute Reference in Excel Macros

Following are some points:

  1. Consistent Result: By using absolute references, you ensure that your macro consistently performs calculations or actions on specific cells, no matter where it is applied.
  2. Flexibility in Positioning: With absolute references, you have the flexibility to place your data and formulas in specific locations within the worksheet.
  3. Enhanced automation: Absolute reference makes your macros more suitable for automated tasks and batch processing.

FAQs on Absolute Reference in Excel Macros

Q1. Which form is preferable, absolute or relative?

Answer:

It depends. Absolute references are in handy when you wish to repeat the same action in the same location across multiple worksheets, or even just the same area of a single worksheet.

When you need to do an action anywhere in a worksheet, relative references come in handy.

Q2. What is the benefit of using absolute cell references?

Answer:

When filling up cells, there may be situations when you don’t want a cell reference to change. Absolute references don’t change when copied or filled in, in contrast to relative references. To maintain the consistency of a row and/or column, utilize an absolute reference.

Q3: Is it possible to mix relative and absolute references in Excel Macros?

Answer:

Yes, we can mix relative and absolute references in Excel macros. A combination of relative and absolute references can help us to create flexible macros that adjust to different cell locations while maintaining fixed references where ever needed.

Q4: How can we test and debug macros with absolute references?

Answer:

You can use the macro step-by-step with the macro debugger or add message boxes to display variable values. This will also help you to verify that the absolute reference is working as intended.



News
Improve
Discuss
Do you want to advertise with us?Click here to know more

Relative References in Excel Macros

article_img
We have two options to refer a cell in Excel VBA Absolute references and Relative references.  Default Excel records macro in Absolute mode. In this article, we learn about Relative references in Excel VBA.  We select a cell “A1”, turn on “Use Relative Reference” and record a macro to type some text in cells B2:B4.   Since we turn on the “Relative reference” option.  Macro considers the number of rows and columns from active cells.  In our example, we select cell A1 and start type B2, which is to move one column and one row from A1 (Active cell). What are Relative References?In Excel, the way of recording actions within a macro that is relative to the cell or range that the macro starts from is known as a relative reference. When you start recording a macro with relative reference, Excel records the actions based on the position of the active cell at the beginning of the macro. The recorded actions will adjust accordingly when the macro is run on different ranges. Using Relative ReferencesWe must make sure that the macro is recorded starting from the cell where the steps must begin in order to record a macro with relative references. ImplementationFollow the below steps to implemen
Read More

Excel Relative and Absolute Cell References

article_img
When working with formulas in Excel, it's crucial to understand the difference between relative and absolute cell references. These two types of cell references behave differently when copied or filled into other cells. Relative cell references change based on their position when a formula is copied to another cell, making them highly useful for repetitive calculations across different rows or columns. Absolute cell references, on the other hand, remain constant regardless of where they are copied, ensuring that a specific cell reference does not change. By mastering both relative and absolute references, you can enhance your Excel skills, making your data management and formula application more efficient. Whether you're a beginner or an experienced user, knowing how to use these references correctly is essential for accurate and effective spreadsheet work. Table of Content What is a Cell Reference in Excel?Types of Cell References in ExcelRelative Reference in ExcelAbsolute Reference in ExcelHow to Use Excel's Relative Reference - Example How to Use Absolute Reference: ExampleHow to use Cell References with Multiple Worksheets in ExcelDifference Between Absolute and Relative cell
Read More

Editing Excel Macros in Excel

article_img
Excel Macro is a set of actions that can be recorded, saved, used multiple times. This feature saves us a lot of time when dealing with repetitive tasks and huge data sets. We can always make changes to an existing Macro in Excel. There are two ways to record and run macros: Excel Commands Excel Visual Basic for Applications(VBA).1. Copying a Macro Code We can reuse the existing macro code while creating new Macros. For example, if you have existing macros created using the record function, we can reuse the code to write new macros. To open the code follow the below steps: Select Tools --> Macros --> Visual Basic Editor. Copy code from the existing macros(use Command + C) and paste(use Command + V) in the new macro2. Renaming a Macro Follow the below steps to rename a Macro in Excel: Select Tools --> Macros --> Visual Basic Editor. Select name on the left plane.Edit the name.3. Deleting a Macro Follow the below steps to delete a macro in Excel: Select Tools --> Macros --> Macros... Select the macro to be deleted. Click on the minus(-) symbol at the bottom.Select yes to delete the macro.
Read More

UserForms in Excel Macros

article_img
A UserFrom refers to a form or a dialog box on the screen that enables a user to input data into Excel's user interface. it can be created using the Visual Basic Editor and is used to control data entry and avoid errors. 1. Creating a UserForm: To create a userform head on to the Developer tab-> Visual Basic->Insert->UserForm. You can also go to the Project window on the left side and right-click the workbook you want to use and select Insert->UserForm. This opens up a blank userform (UserForm1) and a toolbox(if the toolbox doesn't pop up head on to View>toolbox). 2. Naming the UserForm: By default, excel opens up an userform with the name UserForm1 in order to change that name: Head to the Properties window(view>Properties window), This opens a pane on the left.Click on the 'Name' section and type a name of your choice. (don't add spaces)The name won't be reflected on the userform when you do so because that's a different property of the form.Head to the 'Caption' property and type in a name, and it will be reflected on your UserForm. Now let's play with some controls and learn how to add them to our UserForm. 3. Adding a Textbox to the UserForm: A Textbox is use
Read More

How to Configure Macros in Excel

article_img
An action or collection of actions can be recorded, named, stored, and executed as many times as necessary and whenever desired using an Excel macro. We can automate repetitive data manipulation and reporting processes that need to be done repeatedly by using macros. You can record a macro and save it with any name to run it whenever you open the workbook that contains this macro. What are Macros in ExcelMacros in Excel are the recorded sets of actions and these actions can be executed to do repetitive tasks or perform complex operations. A Macro is a sequence of commands or cations that you record, and run whenever needed. Macros in Excel are created using the Virtual Basic for Application(VBA) programming language. How to Create Macros This can be divided in two ways as follows:  1. How to Record a Macro Tip: While recording a Macro the user should be careful because a macro records everything even what went wrong and you have corrected it, so it is advisable to practice the task you want to perform once or twice before recording it.   Recording a Macro is a method that allows you to store the tasks performed by you. To Record a Macro the Developer tab on the Ribbon needs to be a
Read More

How to Automate Repetitive Tasks in Excel Without VBA Macros

article_img
Automating repetitive tasks in Excel can save you significant time and effort, even if you're unfamiliar with VBA macros. Excel offers built-in tools and features that allow users to streamline workflows and reduce manual work without any coding knowledge. From using Power Query for data transformation to Excel formulas, Flash Fill, and built-in automation tools, this guide will show you how to simplify repetitive tasks and boost productivity, all without the complexity of macros. Table of Content Using Excel's Built-In Features for AutomationHow to Excel's Built-In FeaturesIdentify the TaskChoose the Appropriate Built-In Feature Implement the FeatureRecording Macros Without VBA: A Simple GuideAutomating Complex Tasks with Excel's Macro RecorderTesting and Validating Your Excel AutomationsSaving Excel Workbooks with Macro SupportDocumenting Your Excel Automation ProcessesGetting Started with Excel MacrosRecording your First MacroUnderstanding Relative ReferencesEditing and Customizing Macros in ExcelWhy Automate Tasks in Excel Without VBAAutomation in Excel improves productivity, reduces human error, and allows you to focus on analysis rather than manual data entry. While VBA macro
Read More

N

How to Create a Macro in Excel: Build, Run, and Use Macros Easily

article_img
How Do I Create a Macro in Excel- Quick StepsOpen MS Excel > Start Recording a MacroPerform the Actions You Want to Automate > Stop RecordingRun the MacroAre repetitive tasks consuming your time in Excel? With this Excel macros tutorial, you can learn how to create and use macros in Excel to automate tasks and improve efficiency. This guide will walk you through the essentials, from understanding what macros are to creating a macro button for quick access. Whether you're a beginner looking for a step-by-step guide to Excel macros or someone eager to explore advanced features, this article provides everything you need to make and run a macro with ease. Table of Content What is Macro in Excel Uses of Macros in ExcelHow to Create a Macro in ExcelHow to Run a Macro in ExcelHow to Create a Macro button in ExcelEasy Tips for Creating a Macro What is Macro in Excel An Excel Macros is a set of instructions that you can create to automate repetitive tasks. Think of it like a recorded script that performs actions such as formatting cells, entering data, or generating reports, all with just a single click. This helps save time and reduces the chance of errors when doing the same task ov
Read More

How to Enable Macros in Excel (2025): Step-by-Step Guide

article_img
How to Activate Macros in Excel - Quick StepsOpen WorkbookClick Enable Content in the yellow security warning bar.Adjust Macro Settings (Optional):Go to File > Options > Trust Center > Trust Center Settings > Macro Settings.Choose the desired macro setting (e.g., Enable All Macros for trusted files).Save the file .xlsm to retain macros.Macros are an essential feature that helps automate repetitive tasks, making your workflow faster and more efficient. However, since macros involve executing scripts, Excel disables them by default for security reasons. This article provides a simple, step-by-step guide on how to enable macros in Excel, whether you need them for a single session or want to allow them permanently. If you’ve been looking for ways to streamline your tasks while ensuring data security, this guide is for you. Table of Content What Are Macros in Excel and Why Are They Disabled by DefaultStep-by-Step Guide to Enable Macros in ExcelHow to Enable Macros in Excel on MacHow to Change Macro Security Settings in ExcelSecurity Best Practices for Enabling MacrosCommon Issues and Troubleshooting What Are Macros in Excel and Why Are They Disabled by DefaultA macro is a se
Read More

Mixed Cell References in MS Excel

article_img
Cell: The row and column in Excel together make a cell. We input the value/data(s) in cells of a spreadsheet. There are three types of values that can be entered into the cell. NumbersAlphabeticFormulas Cell reference ​​​​​​is the address or name of a cell or a range of cell is known as Cell reference. It is the combination of column name and row number. It helps the software to identify the cell from where the data/value is to be used in the formula. We can reference the cell of other worksheets and also of other programs. Referencing the cell of other worksheets is known as External referencing.Referencing the cell of other programs is known as Remote referencing. There are two types of cell references in Excel: Relative reference.Absolute reference.Mixed Reference Mixed Reference is a type of Absolute reference in which either the column is made constant or the row is made constant. When we make any column or row constant then the column name or row number does not change as we copy the formula to other cell(s). The mixed reference is designated by a dollar sign($) in front of the row or column. For example: $F1: In this the column F is constant.F$1: In this the row 1 is constan
Read More

How to Find Circular References in Excel

article_img
Circular Reference in Excel is like a loop that keeps going around in circles. It happens when a cell's formula depends on its own result, confusing Excel. In this article, you'll learn how to check, find, enable, or remove What is a Circular Reference in Excel?A circular reference in Excel is when a formula is repeated to the same cell, like a no-way-ending loop, where Excel cannot calculate the Formula because it keeps referring back to itself. Circular references can only cause calculation errors and inaccuracies if handled properly with iterative calculation settings or by reworking the formulas to remove the circular reference. Imagine you have math trouble with A, B, and C. A relies upon B and C, after which B and C depend on A. It's like a puzzle wherein you can not find the solution because every piece needs the other. In Excel, this will make calculations messy and wrong. To restore it, you might need to change the formulas or use special settings in Excel. It's like untangling a knot to make certain your math is accurate!  Types of Circular References in ExcelDirect Circular ReferenceIndirect Circular ReferenceThis happens when a component immediately refers to its own
Read More
three90RightbarBannerImg