我看到Range.AutoFill method (Excel)示例:
Set sourceRange = Worksheets("Sheet1").Range("A1:A2")
Set fillRange = Worksheets("Sheet1").Range("A1:A20")
sourceRange.AutoFill Destination:=fillRange
我想在第一个空列(总是第2行)中输入一个公式,然后将该公式复制到寄存器中的所有行(它是从外部源复制的数据)。
Sub SetNextEmptyFormula(strFormula As Variant)
Dim ws As Worksheet
Dim lCol As Long, lRow As Long
Set ws = Workbooks("myworkbook.xlsm").Worksheets("register")
' Always row 2 -> lRow, always in lCol
lCol = ws.Range("A1").End(xlToRight).Column
lRow = ws.Range("A1").End(xlDown).Row
ws.Cells(2, lCol + i).Value = CStr(strFormula)
Set sourceRange = ws.Range(???)
Set fillRange = ws.Range(???)
sourceRange.AutoFill Destination:=fillRange
End Sub
1条答案
按热度按时间67up9zun1#
我不确定你将如何构建你的公式,但是如果你只是在寻找引用这些单元格的帮助,这将是有用的: