我编写了一个宏来列出某些范围之间的所有数字,然后根据每个数字粘贴值。宏抛出运行时错误1004.这是宏:
Sub Populate()
Range("A1") = Range("H18").Value
Range("A1").Select
Selection.DataSeries Rowcol:=xlColumns, Type:=xlLinear, Date:=xlDay, _
Step:=1, Stop:=Range("I18").Value, Trend:=False
Range("J18").Select
Selection.Copy
Range("B1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.Copy
Range("A1").Select
Selection.End(xlDown).Select
Range("B20").Select
Range(Selection, Selection.End(xlUp).Offset(-1, 0)).Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("B1").Select
Range("A1").End(xlDown).Offset(1, 0) = Range("H19").Value
Range("A1").End(xlDown).Select
Selection.DataSeries Rowcol:=xlColumns, Type:=xlLinear, Date:=xlDay, _
Step:=1, Stop:=Range("I19").Value, Trend:=False
Range("J18").Select
Selection.Copy
Range("B1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.Copy
Range("A1").Select
Selection.End(xlDown).Select
Range("B20").Select
Range(Selection, Selection.End(xlUp).Offset(-1, 0)).Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("B1").Select
End Sub
答案 0 :(得分:0)
尝试将语法的开头更改为:
Dim dRange As Range
Set dRange = Range("A1:I18")
Range("A1") = Range("H18").Value
Range("A1").Select
dRange.DataSeries Rowcol:=xlColumns, Type:=xlLinear, Date:=xlDay
由于重复了以下代码,您可能仍会遇到问题:
Range("B20").Select
Range(Selection, Selection.End(xlUp).Offset(-1, 0)).Select
不确定最终目标是什么,但从我的测试中,这可以让您更接近并照顾您的Run-time error: '1004'