[英]Excel Define a range based on a cell value
Is it possible to define a range based on a value given in a cell. 是否可以根据单元格中给定的值定义范围。
So, for example: My selection is A1:A5 That are five cells. 所以,例如:我的选择是A1:A5这是五个单元格。 is it possible to let excel determine this by setting a cell value (like B1) to 5. 是否可以让excel通过将单元格值(如B1)设置为5来确定这一点。
It for the purpose of easily changes a lot of ranges with one change in a cell value. 它的目的是通过单元格值的一次更改轻松更改大量范围。 So if I would change the cell value (B1) to 6. The range would automatically change to A1:A6 因此,如果我将单元格值(B1)更改为6.范围将自动更改为A1:A6
Even more specific, I would like to do it reversed. 更具体一点,我想颠倒过来。
Final example: Selection should be A6:A10 (this are the five cells). 最后一个例子:选择应该是A6:A10(这是五个单元格)。 In B1 I have the value 5. If I change the value of B1 to 6. The range should change to A5:A10 在B1中,我的值为5.如果我将B1的值更改为6.范围应更改为A5:A10
Could somebody help me??? 有人能帮帮我吗???
Say you have number 1,2,3,4,5,6, in cell A1,A2,A3,A4,A5,A6 respectively. 假设您在单元格A1,A2,A3,A4,A5,A6中分别有编号1,2,3,4,5,6。 in cell A7 we calculate the sum of A1:Ax. 在单元格A7中,我们计算A1:Ax的总和。 x is specified in cell B1 (in this case, x can be any number from 1 to 6). x在单元格B1中指定(在这种情况下,x可以是1到6之间的任何数字)。 in cell A7, you can write the following formular: 在单元格A7中,您可以编写以下公式:
=SUM(A1:INDIRECT(CONCATENATE("A",B1)))
CONCATENATE will give you the index of the cell Ax(if you put 3 in B1, CONCATENATE("A",B1)) gives A3). CONCATENATE将为您提供单元格Ax的索引(如果您在B1中放置3,CONCATENATE(“A”,B1))给出A3)。
INDIRECT convert "A3" to a index. INDIRECT将“A3”转换为索引。
see this link Using the value in a cell as a cell reference in a formula? 请参阅此链接使用单元格中的值作为公式中的单元格引用?
You can also use OFFSET: 您也可以使用OFFSET:
OFFSET($A$10,-$B$1+1,0,$B$1)
It moves the range $A$10 up by $B$1-1 (becomes $A$6 ($A$5)) and then resizes the range to $B$1 rows (becomes $A$6:$A$10 ($A$5:$A$10)) 它将范围$ A $ 10上调$ B $ 1-1(成为$ 6 $($ A $ 5)),然后将范围调整为$ B $ 1行(成为$ A $ 6:$ A $ 10($ A $ 5:$ A $ 10))
Here is an option. 这是一个选项。 It works by using making an INDIRECT(ADDRESS(...))
from the ROW
and COLUMN
of the start cell, A1
, down to the initial row + the number of rows held in B1
. 它的工作原理是使用从起始单元格A1
的ROW
和COLUMN
开始的INDIRECT(ADDRESS(...))
,直到初始行+ B1
保存的行数。
SUM(INDIRECT(ADDRESS(ROW(A1),COLUMN(A1))):INDIRECT(ADDRESS(ROW(A1)+B1,COLUMN(A1))))
A1
: is the start of data in a the "A" column A1
:是“A”列中数据的开头
B1
: is the number of rows to sum B1
:是要求和的行数
This should be close to what you are looking for your first example: 这应该接近你想要的第一个例子:
=SUM(INDIRECT("A1:A"&B1,TRUE))
This should be close to what you are looking for your final example: 这应该接近你想要的最后一个例子:
=SUM(INDIRECT("A"&1+B1&":A"&B1,TRUE))
Based on answer by @Cici I give here a more generic solution: 基于@Cici的回答,我在这里给出了一个更通用的解决方案:
=SUM(INDIRECT(CONCATENATE(B1,C1)):INDIRECT(CONCATENATE(B2,C2))) = SUM(INDIRECT(CONCATENATE(B1,C1)):INDIRECT(CONCATENATE(B2,C2)))
In Italian version of Excel: 在意大利语版本的Excel中:
=SOMMA(INDIRETTO(CONCATENA(B1;C1)):INDIRETTO(CONCATENA(B2;C2))) = SOMMA(INDIRETTO(CONCATENA(B1; C1)):INDIRETTO(CONCATENA(B2; C2)))
Where B1-C2 cells hold these values: B1-C2单元格中包含以下值:
You can change these valuese to change the final range at wish. 您可以更改这些值以更改希望的最终范围。
Splitting the formula in parts: 将配方分成几部分:
Hence: 因此:
=SUM(INDIRECT(CONCATENATE(B1,C1)):INDIRECT(CONCATENATE(B2,C2))) = SUM(INDIRECT(CONCATENATE(B1,C1)):INDIRECT(CONCATENATE(B2,C2)))
results in 结果是
=SUM(A1:A5) = SUM(A1:A5)
I'll write down here a couple of SEO keywords for Italian users: 我会在这里写下一些意大利用户的SEO关键词:
Con la formula indicata qui sopra basta scrivere nelle caselle da B1 a C2 gli estremi dell'intervallo per vedelo cambiare dentro la formula stessa. Con la formula indicata qui sopra basta scrivere nelle caselle da B1 a C2 gli estremi dell'intervallo per vedelo cambiare dentro la formula stessa。
Old post but this is exactly what I needed, simple question, how to change it to count column rather than Row. 旧帖但这正是我所需要的,简单的问题,如何将其更改为计数列而不是Row。 Thankyou in advance. 先感谢您。 Novice to Excel. 新手到Excel。
=SUM(A1:INDIRECT(CONCATENATE("A",C5)))
Ie My data is A1 B1 C1 D1 etc rather then A1 A2 A3 A4. 即我的数据是A1 B1 C1 D1等,而不是A1 A2 A3 A4。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.