ML with circles

Mearns Learns

Macro absolute and relative references

When recording a macro, it can be done using absolute references or relative references.

On the Developer tab, to turn on relative references, click on Use Relative References before clicking on Record Macro. To use Absolute references click on Use Relative References so that it is not highlighted.

Macro absolute and relative references Macro absolute and relative references

Absolute References

For absolute references, the macro will always target specific cells.
In the example, when the macro was recorded, cell A1 was copied to cell immediately to its right, B1.
If the macro is run with cell A2 selected, the contents of A2 will be copied to cell B1.

Sub Macro1()
	Selection.Copy
	Range("B1").Select
	ActiveSheet.Paste
	Application.CutCopyMode = False
End Sub

Notice the cell reference of B1.

Relative References

For relative references, the macro will always target cells based on the starting cell.
In the example below, when the macro was recorded, cell A1 was copied to cell immediately to its right, B1.
If the macro is run with cell A2 selected, the contents of A2 will be copied to cell B2.

Sub Macro1_with_relative_references()
	Selection.Copy
	ActiveCell.Offset(0, 1).Range("A1").Select
	ActiveSheet.Paste
	Application.CutCopyMode = False
End Sub

Notice that there is no cell reference, beyond A1 but instead an offset from the Activecell .

Macro absolute and relative references Macro absolute and relative references