我想使用Excel VBA 2016自动绘制累积库存图。
我有不同年份的库存数据,格式为"20XXYY“。这里"XX“表示年份,"YY”表示一年中的周数(1到52)。我将有类似于图片1的数据。然后我想将其分类为图片2。最后将绘图绘制为图片3。但是,我希望使用VBA自动绘制它。



我的问题是,如何为绘图自动创建顺序YearWeek列?
我在“累积库存”栏中使用了“=SUM($Y$2:Y2)”^公式。如果我能得到任何线索,我将不胜感激。
发布于 2019-06-17 22:22:48
“这就是答案。我已经想出来了。谢谢你的支持。”
Sub consecutiveNumber()
Dim wsFrom As Worksheet
Dim Com As String
Dim lLastNumber,FirstNumber, l, i As Long
'change to names of sheets you are coptying from and to
Set wsFrom = ThisWorkbook.Sheets("Sheet1")
'Get the value in the last and first used text box of column A
lLastNumber = wsFrom.Range("A" & Rows.Count).End(xlUp).Value
FirstNumber = wsFrom.Range("A1").Value
'clear column B
wsFrom.Range("B:B").Clear
'Initializing the cell index value
i = 1
'fill column B on sheet 1 with first to last number on column A
For l = FirstNumber To lLastNumber
'Converting number to string
Com = Right(CStr(l), 2)
If CInt(Com) >= 53 Then
l = l + 48
wsFrom.Range("M" & i) = l
i = i + 1
Else
wsFrom.Range("M" & i) = l
i = i + 1
End If
Next
End Subhttps://stackoverflow.com/questions/56621881
复制相似问题