[英]Excel - Replace offset formula with actual cell reference
I have a table that is pulling thousands of rows of data from a very large sheet. 我有一张表从一张非常大的表中提取了数千行数据。 Some of the columns in the table are getting their data from every 5th row on that large sheet.
表中的一些列从该大表上的每第5行获取数据。 In order to speed up the process of creating the cell references, I used an OFFSET formula to grab a cell from every 5th row:
为了加快创建单元格引用的过程,我使用OFFSET公式从每第5行抓取一个单元格:
=OFFSET('Large Sheet'!B$2572,(ROW(1:1)-1)*5,,)
=OFFSET('Large Sheet'!B$2572,(ROW(2:2)-1)*5,,)
=OFFSET('Large Sheet'!B$2572,(ROW(3:3)-1)*5,,)
=OFFSET('Large Sheet'!B$2572,(ROW(4:4)-1)*5,,)
=OFFSET('Large Sheet'!B$2572,(ROW(5:5)-1)*5,,)
etc...
OFFSET can eat up resources during calculation of large tables though, and I'm looking for a way to speed up/simplify my formula. OFFSET虽然可以在计算大表时耗尽资源,但我正在寻找一种方法来加速/简化我的公式。 Is there any easy way to convert the OFFSET formula into just a simple cell reference like:
有没有简单的方法将OFFSET公式转换为一个简单的单元格引用,如:
='Large Sheet'!B2572
='Large Sheet'!B2577
='Large Sheet'!B2582
='Large Sheet'!B2587
='Large Sheet'!B2592
etc...
I can't just paste values either. 我也不能粘贴值。 This needs to be an active reference, because the large sheet will change.
这需要是一个有效的参考,因为大的工作表将会改变。
Thanks for your help. 谢谢你的帮助。
If you want to take a VBA approach to this, you can generate the references very quickly using simple For
loops. 如果要对此采用VBA方法,可以使用简单的
For
循环非常快速地生成引用。
Here is some very crude code which can get you started. 这里有一些非常简洁的代码可以帮助您入门。 It uses hard-coded sheet names and variables.
它使用硬编码的工作表名称和变量。 I am really just trying to show the
i*5
part. 我真的只是想展示
i*5
部分。
Sub CreateReferences()
For i = 0 To 12
For j = 0 To 5
Sheet2.Range("H1").Offset(i, j).Formula = _
"=Sheet1!" & Sheet1.Range("A5").Offset(i * 5, j).Address
Next
Next
End Sub
It works by building a quick formula using the Address
from a reference to a cell on Sheet1
. 它的工作原理是使用
Sheet1
上对Sheet1
格的引用的Address
构建一个快速公式。 The only key here is have one index count cells in the "summary" rows and multiply by 5 to get the reference to the "master" sheet. 这里唯一的关键是在“summary”行中有一个索引计数单元格,并乘以5以获得对“master”表的引用。 I am starting at
A5
just to match the results from INDEX
. 我在
A5
开始只是为了匹配INDEX
的结果。
Results show the formula input for H1
and over. 结果显示
H1
及以上的公式输入。 I am comparing to the INDEX
results generated above. 我正在比较上面生成的
INDEX
结果。
And here is one last approach to this that does not use VBA or formulas. 这是最后一种不使用VBA或公式的方法。 It's just a quick and dirty use of AutoFilter and deleting rows.
这只是对AutoFilter的快速而肮脏的使用并删除行。
Main idea 大意
=Sheet1!A1
and copy it down to match as many rows as there are in the main data. =Sheet1!A1
的引用并将其复制以匹配主数据中的行数。 B1
to be =MOD(ROW(), 5)
B1
添加另一个公式为=MOD(ROW(), 5)
B
and uncheck the 0s (or any single number) B
并取消选中0(或任何单个数字) Some reference images , these are all taken on Sheet2
. 一些参考图像 ,这些都是在
Sheet2
拍摄的。
Formulas with AutoFilter ready. 准备好AutoFilter的公式。
Filtered and ready to delete 已过滤并准备删除
Delete all those rows (select A1
, CTRL+SHIFT+DOWN ARROW, SHIFT+SPACE, CTRL+MINUS) 删除所有这些行(选择
A1
,CTRL + SHIFT +向下箭头,SHIFT + SPACE,CTRL + MINUS)
Delete column B to get final result with "pure" formulas every 5th row. 删除B列,每隔5行用“纯”公式获得最终结果。
Here is one approach using INDEX
instead of OFFSET
. 这是使用
INDEX
而不是OFFSET
一种方法。 I am not sure if it is faster, I guess you can check. 我不确定它是否更快,我想你可以查一下。
INDEX
is not volatile, so you might get some advantage from that. INDEX
不易变,因此您可能从中获得一些优势。
Picture of ranges , you can see that Sheet1
has a lot of data and Sheet2
is pulling every 5th row from that sheet. 范围的图片 ,你可以看到
Sheet1
有很多数据, Sheet2
从该表中每隔5行拉一次。 The data in Sheet1
goes from A1:F1000
and just reports the address of the current cell. Sheet1
的数据来自A1:F1000
,只报告当前单元格的地址。
Formulas use INDEX
and are copied down and across from A1
on Sheet2
. 公式使用
INDEX
并在Sheet2
上从A1
向下复制。
=INDEX(Sheet1!$A$1:$F$1000,ROW()*5,COLUMN())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.