是否有办法使AutoFill增量为10而不是1?下面的代码函数在我的工作表中。用户(地质学家)在B1中定义一个起始站号,在B2中定义一个终端站号。宏运行并以C5开头,列从开始到结束站用站号填充。但是,数据只需要每10个站点收集一次,而我还没有想出如何将其纳入我的代码中。不是1000,1001,1002...etc.,我想要1000,1010,1020.
Sub StationFill()
Dim taskStationEnd As Long
Dim taskStationBegin As Long
taskStationBegin = Range("B1").Value
taskStationEnd = Range("B2").Value
With Worksheets("Data")
.Columns(3).ClearContents
Set SourceRange = .Range("C5")
SourceRange.Value = taskStationBegin
Set fillRange = .Range(SourceRange, _
Cells(SourceRange.Row + taskStationEnd - taskStationBegin, SourceRange.Column))
SourceRange.AutoFill Destination:=fillRange, Type:=xlFillSeries
End With
End Sub(第一次海报。不确定我格式化是否正确,并在正确的位置获得了代码行中断)
发布于 2014-12-03 03:31:18
试试这个:
Sub marine()
Dim taskStationEnd As Long
Dim taskStationBegin As Long
Dim SourceRange As Range
Const interval As Long = 10 '<~~ this is your interval
With Sheets("Sheet1") '<~~ change to suit
taskStationBegin = .Range("B1").Value
taskStationEnd = .Range("B2").Value
Set SourceRange = .Range("C5")
SourceRange = taskStationBegin
SourceRange.Offset(1, 0) = taskStationBegin + interval
SourceRange.Resize(2).AutoFill _
SourceRange.Resize(((taskStationEnd - taskStationBegin) / interval) + 1) _
, xlFillSeries
End With
End Sub发布于 2014-12-03 11:26:57
我尝试过使用Excel 2010,并提供了一个增量值(step)。
Range("A1:A26").DataSeries Rowcol:=xlColumns, Type:=xlLinear, **Step:=10**也许这对你有帮助。
你好,克里斯多夫
https://stackoverflow.com/questions/27263028
复制相似问题