英文:
Excel How to reference a cell then add an offset to its formula (if possible)
问题
我不确定这是否可能,基本上是尝试引用一个单元格的公式,然后将其偏移1个单位(下面的图像可能更好地解释了这个问题)。
我尝试过使用FORMULATEXT
> INDIRECT
> OFFSET(引用,1,0)
,但似乎不起作用。
直接使用OFFSET
也不起作用。
谢谢
英文:
I am not sure if this possible or not, basically trying to reference a cell's formula then add an offset of 1 to it (the image below may explain it better).
I've tried formulatext > indirect > offset(ref,1,0) but it didn't seem to work.
offset direct doesnt work.
Thanks
答案1
得分: 1
你可以很容易地使用VBA来实现这一点:
Sub test()
Range("G1").AutoFill Destination:=Range("G1:G2"), Type:=xlFillDefault
End Sub
这将采用“G1”中的公式,并将其应用于范围“G1:G2”,这与将“G1”中的公式拖动到“G2”相同。
英文:
You can do this quite easily, using VBA:
Sub test()
Range("G1").AutoFill Destination:=Range("G1:G2"), Type:=xlFillDefault
End Sub
This will take the formula in "G1" and apply it over the range "G1:G2", which is the same as dragging the "G1" formula towards "G2".
答案2
得分: 1
你可以使用这个公式:
=LET(f,$G$2, d,A3:H3,
formula,SUBSTITUTE(SUBSTITUTE(FORMULATEXT(f)," ",""),""=",""),
parts,TEXTSPLIT(formula,"+"),
SUM(INDEX(d,,COLUMN(INDIRECT(parts)))))
它期望在G2中有一个包括多个单元格引用的公式,这些引用由加号连接。
该公式提取单个单元格引用,并检索每个单元格引用的列索引。然后使用列索引返回行的单个值。
英文:
You could use this formula:
=LET(f,$G$2, d,A3:H3,
formula,SUBSTITUTE(SUBSTITUTE(FORMULATEXT(f)," ",""),"=",""),
parts,TEXTSPLIT(formula,"+"),
SUM(INDEX(d,,COLUMN(INDIRECT(parts)))))
It expects a formula in G2 that includes multiple cell-references joined by a +-sign.
The formula excerpts the single cell-references and retrieves the column index of each cell reference. Column index is then used to return the single values of the row.
答案3
得分: 1
I will only translate the requested content:
自从我在对Inkca的评论中注意到(而不是在问题本身中),您想要使用偏移量,因为您希望能够更改总和中参考单元格的行偏移量,我也想分享这个选项:
=LET(shift, 1,
b,TEXTSPLIT(FORMULATEXT(G1),{"+","="},,1),
SUM(OFFSET(INDIRECT(b),shift,)))
这样,您可以轻松更改偏移量的数量。
您还可以引用一个包含shift
值的单元格,例如G2
:
=LET(shift, G2,
b,TEXTSPLIT(FORMULATEXT(G1),{"+","="},,1),
SUM(OFFSET(INDIRECT(b),shift,)))
未来问题的建议是更好地阐明问题的目标。请注意问题本身会导致很多问题。
英文:
Since I noticed in your comments to Inkca (not in the question itself) you wanted to use offset because you wanted to be able to change the offset of rows from the referenced cells in your sum, I wanted to share this option as well:
=LET(shift, 1,
b,TEXTSPLIT(FORMULATEXT(G1),{"+","="},,1),
SUM(OFFSET(INDIRECT(b),shift,)))
This way you can easily change the number of shift to change the offset.
You could also reference a cell that holds the shift
value, for instance G2
:
=LET(shift, G2,
b,TEXTSPLIT(FORMULATEXT(G1),{"+","="},,1),
SUM(OFFSET(INDIRECT(b),shift,)))
Tip for future questions is to better formulate the goal of your question. Note the many questions as a result of the question itself.
答案4
得分: 0
Would OFFSET(B1,1,)+OFFSET(D1,1,) do the job?
或者稍微更加灵活...
=OFFSET(B1,ROW()-1,)+OFFSET(D1,ROW()-1,)
我不确定你所说的“无论在G1中选择什么,都会在G2中计算+1”是什么意思。
英文:
Would OFFSET(B1,1,)+OFFSET(D1,1,) do the job?
Or slightly more expandable...
=OFFSET(B1,ROW()-1,)+OFFSET(D1,ROW()-1,)
I'm unsure what you mean by "Whatever is selected in G1 is then calc+1 in G2"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论