Formula with an ActiveCell

S

Sok Hong

Hi, I am trying to input a formulae into a cell that
references to an activeCell. Currently this is the
formulae I have in there, but it's giving me errors. Any
thoughts on how I can do this?

ActiveCell.FormulaR1C1 =

"=Cells(32,ActiveCell.Column).Select*(R16C4)*(R9C3)"
 
D

Dave Peterson

I think you're looking for:

ActiveCell.FormulaR1C1 = _
"=" & Cells(32, ActiveCell.Column).Address(ReferenceStyle:=xlR1C1) _
& "*(R16C4)*(R9C3)"

But since you know the row and column number, this looks simpler:

ActiveCell.FormulaR1C1 = "=r32c" & ActiveCell.Column & "*(r16c4)*(r9c3)"

Both of these put the reference in the cell--not the value. Each of these
result in a formula like:
=$F$32*($D$16)*($C$9)

If you really wanted the value, then maybe:

ActiveCell.FormulaR1C1 = _
"=" & Cells(32, ActiveCell.Column).Value & "*(R16C4)*(R9C3)"

This formula looks like: =33*($D$16)*($C$9)
 
T

Tom Ogilvy

ActiveCell.FormulaR1C1 = _
"=" & Cells(32,ActiveCell.Column).Address(True,True,xlR1C1) _
& "*(R16C4)*(R9C3)")
 
B

BrianB

You cannot do that. ActiveCell is a VBA object - not recognised by
normal Excel. You can only access the active cell at runtime with
something like :-
Range("A1").Value = ActiveCell.Value


Regards
BrianB
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top