Solved

Relative vs Absolute Cell Reference with VBA

Posted on 2013-10-24
2
969 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

705 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now