问题
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).
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:
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.
Thanks very much in advance for your help!
回答1:
You can try to use Autofill
with a destination range.
Something like:
Selection.AutoFill Destination:=Range("A2:A12")
[EDIT] Or:
Range("A1").AutoFill Destination:=Range(Cells(1, firstColNumber), Cells(1, lastColNumber))
来源:https://stackoverflow.com/questions/7889987/excel-2010-vba-autofill-entire-column