Excel 2010 VBA 自动填充整列
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7889987/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Excel 2010 VBA Autofill entire column
提问by Derek
I am having trouble getting VBA to do the equivalent of Autofilling an entire row (such as when you double click on the plus sign of a cell with a formula and it autofills the appropriate number of columns).
我无法让 VBA 执行相当于自动填充整行的操作(例如,当您双击带有公式的单元格的加号并自动填充适当数量的列时)。
Along Column A I have a list of dates. Along Row 3 I have a list of formulas. How do I write a macro which will effectively do this:
沿着列 AI 有一个日期列表。沿着第 3 行,我有一个公式列表。我如何编写一个可以有效执行此操作的宏:
For i = 2 to Columns.Count
'FillDown the whole of Column i with the formula in Cells(3,i)
Next i
I want the fill down, not just a copy of the exact formula... Does anyone know how this can be done? I've got a method which is taking about 20 minutes so far but when I do this process manually it takes not very much time at all, so I think there must be a much faster way.
我想要填充,而不仅仅是精确公式的副本......有谁知道如何做到这一点?到目前为止,我有一种方法大约需要 20 分钟,但是当我手动执行此过程时,它根本不需要太多时间,因此我认为必须有更快的方法。
Thanks very much in advance for your help!
非常感谢您的帮助!
回答by JMax
You can try to use Autofill
with a destination range.
您可以尝试使用Autofill
目标范围。
Something like:
就像是:
Selection.AutoFill Destination:=Range("A2:A12")
[EDIT] Or:
[编辑] 或:
Range("A1").AutoFill Destination:=Range(Cells(1, firstColNumber), Cells(1, lastColNumber))