ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

ActiveChart.SetSourceData ¨Ó·½¸ê®Æ°ÝÃD (¤v¸Ñ¨M)

¦^´_ 2# FAlonso
[·|¥X²{«¬ºA¤£²Å¦XªºÄµ¸¹,¸Ó¦p¦óÁ×§K?]
§Aªº¿ù»~¦b©ó­ì¥»ªºµ{¦¡¦b°õ¦æ®É
ActiveSheet.Selection ¬O .ChartObjects(1) ¦Ó¤£¬O RANGE

­×§ï§Aªºµ{¦¡¦p¤U
b2 b3 ½Ðª½±µ¿é¤J¤é´Á §Y¥i

   
  1. Sub plotgraph()
  2. Dim myrange As Range, error As Boolean, x As Integer, y As Integer
  3. Dim Rng As Range
  4. error = False
  5. x = 0
  6. y = 0
  7. With Sheet1
  8.     .Activate
  9.     .[a1].Activate   
  10.      '[·|¥X²{«¬ºA¤£²Å¦XªºÄµ¸¹,¸Ó¦p¦óÁ×§K?]
  11.     '§Aªº¿ù»~¦b©ó­ì¥»ªºµ{¦¡¦b°õ¦æ®É
  12.     'ActiveSheet.Selection ¬O .ChartObjects(1) ¦Ó¤£¬O RANGE
  13.     Set Rng = .Range(.[a8], .[a65536].End(xlUp))
  14.     If .[b2] = "" Or .[b3] = "" Then
  15.         MsgBox "No date"
  16.         error = True
  17.     ElseIf .[b2] > .[b3] Then
  18.         MsgBox .[b2] & ">" & .[b3]
  19.         error = True
  20.     ElseIf Rng(1) > .[b2] Then
  21.         MsgBox "Before starting period"
  22.         error = True
  23.     ElseIf .[b3] > Rng(Rng.Count) Then
  24.         MsgBox "After ending period"
  25.         error = True
  26.     End If
  27.     If error = True Then Exit Sub
  28.     For Each myrange In Rng
  29.         If myrange >= .[b2] Then
  30.             x = myrange.Row - 1
  31.             Exit For
  32.         End If
  33.     Next
  34.     For Each myrange In Rng
  35.         If .[b3] <= myrange Then
  36.             y = myrange.Row - 1
  37.             Exit For
  38.         End If
  39.     Next
  40.     If Sheet1.ChartObjects.Count = 0 Then Charts.Add
  41.     .ChartObjects(1).Select
  42.     ActiveChart.ChartType = xlLineMarkers
  43.     ActiveChart.Location xlLocationAsObject, Name:="Sheet1"
  44.     ActiveChart.HasDataTable = False
  45.     .Activate
  46.     If [b4] = "¶}½L" Then
  47.         ActiveChart.SetSourceData Source:=.Range("A" & x & ":A" & y & ",B" & x & ":B" & y), PlotBy:=xlColumns
  48.     ElseIf .[b4] = "³Ì°ª" Then
  49.         ActiveChart.SetSourceData Source:=.Range("A" & x & ":A" & y & ",C" & x & ":C" & y), PlotBy:=xlColumns
  50.     ElseIf .[b4].Value = "³Ì§C" Then
  51.         ActiveChart.SetSourceData Source:=.Range("A" & x & ":A" & y & ",D" & x & ":D" & y), PlotBy:=xlColumns
  52.     ElseIf .[b4].Value = "¦¬½L" Then
  53.         ActiveChart.SetSourceData Source:=.Range("A" & x & ":A" & y & ",E" & x & ":E" & y), PlotBy:=xlColumns
  54.     End If
  55. End With
  56. End Sub
½Æ»s¥N½X

TOP

        ÀR«ä¦Û¦b : §Ñ¥\¤£§Ñ¹L¡A§Ñ«è¤£§Ñ®¦¡C
ªð¦^¦Cªí ¤W¤@¥DÃD