Solved

Relative vs Absolute Cell Reference with VBA

Posted on 2013-10-24
2
1,017 Views
Last Modified: 2013-10-24
Dear Experts

Simple Line of Code to enter a formula in the active cell using VBA

Sub RelativeCellReference()
    
    ActiveCell = "=Trim(RC" & 1 & ")"

End Sub

Open in new window


I want this formula to mean Active cell = value of cell in active row, column 1
The formula that is being returned is relative both to column and row.

If i type the formula directly into the active cell. I.e Trim(RC1) it returns the correct answer.

What in the name of all that is VBA am I doing wrong.  Wood, trees etc....
Help

Thank you
David
RelativeCellReference.xlsm
0
Comment
Question by:David Phelops
2 Comments
 
LVL 6

Accepted Solution

by:
Michael earned 500 total points
ID: 39597226
Hello David,

Try this:

Sub RelativeCellReference()
    
    ActiveCell.FormulaR1C1 = "=Trim(RC" & 1 & ")"

End Sub

Open in new window


Without the .FormulaR1C1, Excel thinks you want to Trim column RC row 1.

JazzyJoop
0
 

Author Closing Comment

by:David Phelops
ID: 39597254
Works for me too.  :-) phew.

Makes sense now.  First time that actually I see the practical value of "FormulaR1C1"

Many thanks. Most appreciated
David
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question