0 votes
in VBA by Beginner (23 points)
“Use Relative References “ in code group under Developer tab

1 Answer

0 votes
by Skilled (401 points)

Hello

With the Recording Macro approach I have recorded simple code to illustrate the difference to you

Sub Macro1()
'
' Macro1 Macro
'

'
    ActiveCell.Offset(0, 1).Range("A1").Select
    ActiveCell.FormulaR1C1 = "Yasser"
    ActiveCell.Offset(0, 1).Range("A1").Select
End Sub

Sub Macro2()
'
' Macro2 Macro
'

'
    Range("D13").Select
    ActiveCell.FormulaR1C1 = "Yasser"
    Range("E13").Select
End Sub

As you see, with activating the Relative Reference, the macro deal with any cell using Offset function. But without using it the macro records the cell reference in absolute reference using the cell addresses directly.

by Beginner (23 points)
Got it, thanks.

Another related question: OFFFSET is a volatile worksheet function.

Is OFFFSET also volatile when used in VBA code to say make a ToC in an excel  worksheet?
by Skilled (401 points)
That depends on the use of OFFSET. But I think it is different from the OFFSET volatile worksheet function.
by Beginner (23 points)

I believe that OFFFSET is not volatile when used in any VBA code.

by Skilled (401 points)
But use it for necessary purposes

Welcome to wellsr Q&A
wellsr Q&A is the VBA and Python programming community that rewards you for learning how to code.

Earn free prizes for asking VBA and Python questions and for answering questions asked by others in our community.

What makes us different?
Our points system rewards you with a chance for free gifts based on the quality of your questions and/or answers. Users that ask great questions, may be given complimentary gift cards or training material.

Getting Started
Register

So, why don't you join us? It really is a neat way to reward the most dedicated members in our VBA and Python community.

For more programming tips visit the VBA Tutorials Blog and the Python Tutorials Blog.

...