返回列表 上一主題 發帖

[發問] 如何將產生的圖表存放在指定工作表的位置上呢?

回復 1# dechiuan999
  1. Private Sub CommandButton1_Click()
  2. Dim mRng As Range
  3.     Dim mRng1 As Range
  4.     Dim mRng2 As Range
  5.     Dim mRng3 As Range
  6.     Dim mTotal%
  7.     Dim oldMonth
  8.     Dim mSht As Worksheet
  9.     Dim mRow As Integer
  10.         
  11.     Set mSht = Worksheets(1)
  12.     With mSht
  13.         mRow = .Range("a1").End(xlDown).Row
  14.         Set mRng = .Range("g1:l" & mRow)
  15.         Set mRng1 = .Range("a2:a12")
  16.         Set mRng2 = .Range("f2:f12")
  17.         mTotal = Application.WorksheetFunction.Max(mRng2)
  18.         Set mRng3 = Union(mRng1, mRng2)
  19.     End With
  20.    
  21.     oldMonth = Month(Date) - 1
  22.     Application.ScreenUpdating = False
  23.     '新增圖表之X位置 Y位置 寬 高
  24.     Set mychart = Sheet1.ChartObjects.Add(350, 0, 400, 200)
  25.    
  26.     Select Case mTotal
  27.     Case 1 To 100
  28.         mTotal = "100"
  29.     Case 101 To 200
  30.         mTotal = "200"
  31.     Case 201 To 300
  32.         mTotal = "300"
  33.     Case 301 To 400
  34.         mTotal = "400"
  35.     Case 401 To 500
  36.          mTotal = "500"
  37.     Case esle
  38.         mTotal = mTotal
  39.     End Select
  40.    
  41.     With mychart.Chart
  42.         .SetSourceData Source:=mRng3, PlotBy:=xlColumns
  43.         .HasTitle = True
  44.         .ChartType = xlColumnClustered
  45.         .HasLegend = False
  46.         .ApplyDataLabels xlDataLabelsShowValue
  47.         '.Axes(xlCategory).TickLabels.Orientation = xlHorizontal
  48.         .ChartTitle.Characters.Text = oldMonth & " 月份統計表"
  49.         .ChartTitle.Font.Bold = False
  50.         .ChartTitle.Font.Size = 12
  51.         .PlotArea.Top = 16
  52.         .PlotArea.Height = 160
  53.         .Axes(xlValue).MaximumScale = mTotal
  54.         .Axes(xlCategory, xlPrimary).HasTitle = False
  55.         .Axes(xlValue, xlPrimary).HasTitle = False
  56.         .ChartArea.Font.Size = 8
  57.         .ChartTitle.Font.Size = 10
  58.      End With
  59.    
  60.     Application.ScreenUpdating = True

  61. End Sub
複製代碼
TEST二.rar (13.05 KB)

TOP

回復 4# dechiuan999


Set Rng = Range("H1:L12")   
則Rng(1)=Range("H1")
   Rng(2)=Range("I1")
   Rng(6)=Range("H2")
...先橫再直 之排列方式
為儲存格之另一種表示法

TOP

        靜思自在 : 人的心地是一畦田,土地沒有播下好種子,也長不出好的果實。 -
返回列表 上一主題