我试图在VBA上设置此自动填充范围,但我不知道什么是错误的,即使它可以正常工作也是如此。它应基于每列的第一和第二单元格填充所有范围A1至Z20。如果其他任何人都可以使用它,或者出了什么问题,请修复它。
Sub test()
Dim i As Range
Dim a As Long
Do While Not Range("Z20").Value > 0
If a = 0 Then
a = 1
Else
End If
For Each i In Range("A:Z")
a = a + 1
i = Range(Cells(1, a), Cells(20, a))
Cells(1, a).Value = 1
Cells(2, a).Value = 2
Set SourceRange = Range(Cells(1, a), Cells(2, a))
Set fillRange = Range(i).Columns(a)
SourceRange.AutoFill Destination:=fillRange
Next
Loop
End Sub
Option Explicit
Sub test()
Dim c As Range
Dim a As Long
Dim sourceRange As Range
a = 1
Do While a <> 20
ActiveSheet.Cells(1, a) = 1
ActiveSheet.Cells(2, a) = 2
Set c = ActiveSheet.Range(Cells(1, a), Cells(20, a))
Set sourceRange = ActiveSheet.Range(Cells(1, a), Cells(2, a))
sourceRange.AutoFill Destination:=c
a = a + 1
Loop
End Sub
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句