0

如果我有这个,例如:

Sub ExampleThing()

    Counter = 13
    For i = 1 To Counter
        Range("A" & i) = Rnd
    Next

    Range("B1").Formula = "=(PI()*A1)"
    Range("B1").Select
    Selection.AutoFill Destination:=Range("B1:B" & Counter), Type:=xlFillDefault

End Sub

如果我想使用 Cells(),而不是使用 Destination 下的 Range(),该怎么办?就像,不是在 range 函数中使用单元格引用,而是用 Cells() 替换它,如下所示:

Selection.AutoFill Destination:=Range("Cells(1,2):Cells(Counter,2)"), Type:=xlFillDefault

我一直在玩它,似乎无法让它工作。

4

1 回答 1

1

你很亲密。这是一个声明了变量的版本(您确实应该这样做)并Select消除了语句(也是一个好习惯):

Sub ExampleThing()
Dim Counter As Long
Dim i As Long

Counter = 13
For i = 1 To Counter
    Range("A" & i) = Rnd
Next
Range("B1").Formula = "=(PI()*A1)"
Range("B1").AutoFill Destination:=Range(Cells(1, 2), Cells(Counter, 2)), Type:=xlFillDefault
End Sub
于 2013-06-25T19:54:04.140 回答