简体   繁体   English

绝对引用 - 在以R1C1表示法编写的等式中插入等效的'$'

[英]Absolute referencing - Inserting the equivalent of '$' in an equation written in R1C1 notation

I have this equation that I am using VBA to enter into a cell on my spreadsheet: 我有这个等式,我使用VBA进入我的电子表格中的单元格:

ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-3],RC[-1]:R[" & CellNumber & "]C[-1],1,0)"

How do I have it enter the formula with $ signs to keep the cell references locked? 如何输入带有$符号的公式以保持单元格引用被锁定?

I tried adding $ s in their respective positions in the formula but that didn't work. 我尝试在公式中各自的位置添加$ s,但这不起作用。

If not yet maybe one day you may notice the difference is that absolute references (i) do not use square brackets and (ii) always have a number immediately to the right of R and C , eg R1C1, which means Row 1, Column1 – usually expressed A1 (though sometimes R1C1 in the spreadsheet itself, as well as in a macro - when in what is termed R1C1 reference style). 如果还不到一天你可能会注意到差异是绝对引用(i)不使用方括号和(ii)在RC的右边总是有一个数字,例如R1C1,这意味着第1行,第1列 -通常表达A1 (虽然有时在电子表格本身的R1C1 ,以及在宏中 - 当在所谓的R1C1参考样式时)。

RC[-3] is a relative reference and means whatever row happens to be the current one (no value immediately to the right of R , so no offset from the current row) and three columns to the left (because negative) of whatever happens to be the current column. RC[-3]是一个相对引用,意味着任何行恰好是当前行( R的右边没有值,所以没有偏离当前行)和左边的三列(因为负数)成为当前专栏。

So if in D1 , RC[-3] references exactly the same location as R1C1 does – ie what is generally known as A1 . 因此,如果在D1RC[-3]引用与R1C1完全相同的位置 - 即通常称为A1

However because a relative reference, put RC[-3] in E1 and it will reference B1 , whereas R1C1 (as does $A$1) refers to A1 wherever it is placed. 但是因为相对参考,将RC[-3]放在E1并且它将引用B1 ,而R1C1 (和$ A $ 1一样)在任何地方都指向A1

Now, your example mentions Active Cell - that is where you formula will be placed and is the start point for "in the same row but three columns to the left". 现在,您的示例提到了Active Cell - 这是您将放置公式的位置,并且是“在同一行但左侧三列”的起点。 But you have not shown how the active cell was selected so we can't tell which cell to start from, therefore the location (rather than the direction/distance away) where you want to end up. 但是你还没有展示如何选择活动单元格,因此我们无法确定从哪个单元格开始,因此无法确定要结束的位置(而不是方向/距离)。

If on a chessboard for example, relative references might be "move your knight two rows up and one column to the right" whereas absolute would be "put your knight in square King 4". 例如,如果在棋盘上,相对引用可能是“将你的骑士向上移动两行,向右移动一列”,而绝对将“将你的骑士放在方形王4”中。

In a sense, both 'systems' are relative – just that the "absolute" one is always relative to the top left-hand corner (except when using RTL layout). 从某种意义上说,两个“系统”都是相对的 - 只是“绝对”系统总是相对于左上角(使用RTL布局时除外)。

It might help to think of the square brackets together [ ] as "from the cell I am in". 可能有助于将方括号[ ]视为“来自我所在的单元格”。

The equivalent of 'negative columns means to the left' for rows is 'up'. 行的“负列表示左侧”等效于“向上”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM