Excel How to reference a cell then add an offset to its formula (if possible)

huangapple go评论62阅读模式
英文:

Excel How to reference a cell then add an offset to its formula (if possible)

问题

我不确定这是否可能,基本上是尝试引用一个单元格的公式,然后将其偏移1个单位(下面的图像可能更好地解释了这个问题)。

Excel How to reference a cell then add an offset to its formula (if possible)

我尝试过使用FORMULATEXT > INDIRECT > OFFSET(引用,1,0),但似乎不起作用。

直接使用OFFSET 也不起作用。

谢谢 Excel How to reference a cell then add an offset to its formula (if possible)

英文:

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).

Excel How to reference a cell then add an offset to its formula (if possible)

I've tried formulatext > indirect > offset(ref,1,0) but it didn't seem to work.

offset direct doesnt work.

Thanks Excel How to reference a cell then add an offset to its formula (if possible)

答案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.

Excel How to reference a cell then add an offset to its formula (if possible)

答案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,)))

Excel How to reference a cell then add an offset to its formula (if possible)

未来问题的建议是更好地阐明问题的目标。请注意问题本身会导致很多问题。

英文:

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,)))

Excel How to reference a cell then add an offset to its formula (if possible)

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"

huangapple
  • 本文由 发表于 2023年6月13日 16:22:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/76462984.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定