You are learning Macros in MS Excel
How to record relative vs absolute references in macros?
By default, Excel macros record relative references. This means the cell references recorded in the macro will be relative to the starting position of the macro recording.
Here's how it works:
* Imagine you record a macro that copies the value from cell B2 and pastes it into cell C3.
* When you replay the macro on a different cell (e.g., starting at A5), it will copy from cell A2 (one column left and two rows up relative to the starting cell) and paste into B3 (one column right and same row relative to the starting cell).
Here's how to record absolute references in macros:
1. Enable Absolute Recording: Before starting your macro recording, find the "Relative Recording" button on the recording toolbar (usually appears near the top of the screen). It might look like a little square with an arrow in the corner. Click this button to toggle it off. Now, your macro will record absolute references.
2. Record the Macro: With absolute recording enabled, perform the actions you want to record. When referencing cells, they will be recorded as their exact addresses (e.g., $B$2, $C$3).
3. Replay the Macro: The macro will always reference the specific cells you recorded, regardless of where it's played back in the worksheet.
Here are some additional points to consider:
* You can switch between relative and absolute recording within the same macro by toggling the button on/off during recording.
* It's generally recommended to use relative references for more versatile macros that can be used in different parts of your worksheet.
* Absolute references are useful when you need to target specific cells no matter where the macro is run.
For more advanced control, you can also manually edit the recorded VBA code of the macro to change references from relative to absolute and vice versa.