Solved

Relative vs Absolute Cell Reference with VBA

Posted on 2013-10-24
2
1,046 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
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…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

734 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