Full Version: mystery characters
UtterAccess Discussion Forums > Microsoft® Office > Microsoft Excel
dday76
So I've got an excel workbook. I've got a module where I input the code below.

CODE
    Range("E1").Select
    ActiveCell.FormulaR1C1 = _
        "=IF(RC[13]>0,MIN(ROUNDDOWN(Control!N7/RC[16],0),RC[13]))"


I run the macro, and Lo and behold, praise the lord, a miracle occurs, and in my spreadsheet, I get things like this:

CODE
=IF(R3>0,MIN(ROUNDDOWN(Control!'N7'/U3,0),R3))


Now I'm totally ok with RC[] returning cell references, but getting 'N7' instead of N7 is breaking my reference. What is going on?

Jason
norie
Jason

Your mixing R1C1 and A1 referencing when trying to create a R1C1 reference using the FormulaR1C1 property.

What should N7 be in R1C1 referencing?
dday76
Ah yes. I guess I am.

I tried using the R1C1 reference, but it's supposed to be a nonchanging reference. Actually I would want it to be $N$7.

the thing is, this formula gets mass pasted, so the relative references are important as well. Can I get one absolute reference and one relative reference?


Jason
dday76
So the solution I found was to declare a variable, set the variable equal to the absolute cell reference, and concatenate the variable into the FormulaR1C1 expression.

"=IF(RC[13]>0,MIN(ROUNDDOWN(" & NewVariable & "/RC[16],0),RC[13]))"
norie
This worked for me.
CODE
Range("E1").FormulaR1C1 = "=IF(RC[13]>0,MIN(ROUNDDOWN(Control!R7C14/RC[16],0),RC[13]))"

I think the key to absolute/relative referencing in R1C1 notation is the [].

By the way the R in RC[13] is being treated as column R.dazed.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.