我在Excel中有一組數據。人口以年爲單位數百萬,但是我需要填寫的數據存在差距。看下面的例子用於線性系列填充的Excel宏
Year--2013--2014--2015--2016--2017--2018--2019--2020
Male-- 5-- -- 7-- -- -- 8-- -- 10
Fem-- 4-- -- 5-- -- -- 7-- -- 9
我知道我可以使用填充/系列/線性,但我需要從2000年至2050年爲數百個國家做到這一點。我試圖記錄我這樣做的宏,但Step Value似乎是硬編碼的。
這是甚至可能或我咬牙,繼續手動?
感謝
Ĵ
Sub FillTheGaps()
'
' fill the gaps Macro
'
'start at cell A2
'find first gap on that row
Selection.End(xlToRight).Select
'select up to and including next non-blank
Range(Selection, Selection.End(xlToRight)).Select
Selection.DataSeries Rowcol:=xlRows, Type:=xlLinear, Date:=xlDay, Step _
:=11845, Trend:=False
Selection.End(xlToLeft).Select
'move down to next row
ActiveCell.Offset(1).Select
Selection.End(xlToRight).Select
'select up to and including next non-blank
Range(Selection, Selection.End(xlToRight)).Select
Selection.DataSeries Rowcol:=xlRows, Type:=xlLinear, Date:=xlDay, Step _
:=8598, Trend:=False
Selection.End(xlToLeft).Select
'move down to next row
ActiveCell.Offset(1).Select
Selection.End(xlToRight).Select
'select up to and including next non-blank
Range(Selection, Selection.End(xlToRight)).Select
Selection.DataSeries Rowcol:=xlRows, Type:=xlLinear, Date:=xlDay, Step _
:=30400, Trend:=False
'move down to next row
ActiveCell.Offset(1).Select
End Sub
爲什麼不告訴我們你錄製的內容?所有來自宏錄像機的*都是*硬編碼的,但通常它可以很容易地修改... – 2014-10-27 15:32:20
我現在已經包含了我記錄的宏,這有幫助嗎? – jellybean1977 2014-10-28 10:38:07
步數值代表什麼?如果你能確定它們是如何分配的,應該很容易把它放在一個循環中。 – 2014-10-28 13:55:50