领动网站建设谷歌seo是什么职业
1. 对商品库存的需求分析
代码段1-计算需求量并影藏无关行
Public Sub DemandCalc()Application.ScreenUpdating = False
'定义用于循环的整型变量
Dim i As IntegerFor i = 2 To 72'判断库存量是否小于订购量If Cells(i, 4) < Cells(i, 5) Then'如果小于,则计算“需求量”Cells(i, 6) = Cells(i, 5) - Cells(i, 4)'选择"需求量"单元格Cells(i, 6).Select'为库存不足的"需求量"单元格设置底色Selection.Interior.ColorIndex = 15Else'选择第i行Rows(i).Select'把库存剩余的行“隐藏”Selection.EntireRow.Hidden = TrueEnd IfNext iApplication.ScreenUpdating = True
End Sub
2. 对月销售情况进行分析
代码段2-汇总计算及图表绘制
Public Sub MonthlyCalc()Application.ScreenUpdating = False
'定义用于循环的整型变量
Dim Itemp As Integer
Dim ChartTypeArray() As Variant
Dim ChartCount As IntegerFor Itemp = 1 To 12'计算商品(甲)的销售额合计Cells(4, Itemp + 2) = Cells(2, Itemp + 2) * Cells(3, Itemp + 2)'计算商品(乙)的销售额合计Cells(7, Itemp + 2) = Cells(5, Itemp + 2) * Cells(6, Itemp + 2)'计算商品(丙)的销售额合计Cells(10, Itemp + 2) = Cells(8, Itemp + 2) * Cells(9, Itemp + 2)'计算三种商品总的销售额合计Cells(11, Itemp + 2) = Cells(4, Itemp + 2) + Cells(7, Itemp + 2) _+ Cells(10, Itemp + 2)Next ItempChartTypeArray = Array(xlLineMarkers, xlLineMarkersStacked, xlLineMarkersStacked100)ChartCount = 1Do While (ChartCount <= (UBound(ChartTypeArray, 1) + 1))'添加图表Charts.Add'定义图表类型ActiveChart.ChartType = ChartTypeArray(ChartCount - 1)'图表数据源ActiveChart.SetSourceData Source:=Sheets("chap5_2").Range( _"A1:N1,A4:N4,A7:N7,A10:N10"), PlotBy:=xlRows'设置图表添加的位置ActiveChart.Location Where:=xlLocationAsObject, Name:="chap5_2"With ActiveChart'使图表带有“标题”.HasTitle = True'设置图表“标题”.ChartTitle.Characters.Text = "月销售情况对比"'使图表带有X坐标标题.Axes(xlCategory, xlPrimary).HasTitle = True'设置图表X坐标标题.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "月份"'使图表带有Y坐标标题.Axes(xlValue, xlPrimary).HasTitle = True'使图表带有Y坐标标题.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "合计(元)"End WithWith ActiveChart.Parent.Left = 10 + 368 * (ChartCount - 1) '此处用以修改图表在工作表中的位置.Top = 200End WithChartCount = ChartCount + 1LoopApplication.ScreenUpdating = True
End Sub
效果图:
后记:
这个例子耗费了我两三个小时,不过也值了。学会了如何自动插入多张Excel图表。