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

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

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

¥»©«³Ì«á¥Ñ FAlonso ©ó 2011-3-13 15:21 ½s¿è

¾Þ§@­ì·N¬O¦bB2¿ï¾Ü¶}©l¤é´Á,B3¿ï¾Üµ²§ô¤é´Á,B4¿ï¾Ü¼Æ¾Ú¦C(¨Ò¦p³Ì°ª­È,³Ì§C­È)µ¥,¦A³z¹Lµ{¦¡Ã¸µe¸Ó¼Æ¾Ú¦Cªº¹Ïªí

¥H¤Uµ{¦¡¦¨¥\¹B¦æ
  1. Sub plotgraph()
  2. Dim myrange As Range, error As Boolean, x As Integer, y As Integer, mycolumn, mytitle
  3. With Sheet1
  4. .Activate
  5. .[a1].Activate
  6. End With

  7. error = False
  8. x = 0
  9. y = 0
  10. mytitle = [b4].Value

  11. If [b2] = "" Or [b3] = "" Then
  12. MsgBox "No date"
  13. Exit Sub
  14. End If

  15. If DateValue([a8]) > DateValue([b2]) Then
  16. MsgBox "Before starting period"
  17. error = True
  18. End If

  19. If DateValue([b3]) > DateValue([a41]) Then
  20. MsgBox "After ending period"
  21. error = True
  22. End If

  23. If error = True Then
  24. Exit Sub
  25. End If

  26. For Each myrange In Range([a8], [a65536].End(xlUp))
  27. If DateValue(myrange) >= DateValue([b2]) Then
  28. x = myrange.Row
  29. Exit For
  30. End If
  31. Next

  32. For Each myrange In Range([a8], [a65536].End(xlUp))
  33. If DateValue(myrange) > DateValue([b3]) Then
  34. y = myrange.Row - 1
  35. Exit For
  36. End If
  37. Next

  38. If mytitle = "¶}½L" Then
  39.     mycolumn = "B"
  40. ElseIf mytitle = "³Ì°ª" Then
  41.     mycolumn = "C"
  42. ElseIf mytitle = "³Ì§C" Then
  43.     mycolumn = "D"
  44. ElseIf mytitle = "¦¬½L" Then
  45.     mycolumn = "E"
  46. End If

  47. Sheet1.ChartObjects(1).Select
  48. ActiveChart.HasTitle = True
  49. ActiveChart.ChartTitle.Text = mytitle
  50. ActiveChart.HasLegend = False
  51. ActiveChart.SetSourceData Source:=Sheet1.Range("A" & x & ":" & "A" & y & "," & mycolumn & x & ":" & mycolumn & y), PlotBy:=xlColumns

  52. With Sheet1
  53. .Activate
  54. .[a1].Activate
  55. End With

  56. End Sub
½Æ»s¥N½X
80 ¦r¸`¥H¤º
¤£¤ä«ù¦Û©w¸q Discuz! ¥N½X

¥»©«³Ì«á¥Ñ FAlonso ©ó 2011-3-13 15:22 ½s¿è

½Ð°Ñ¦Ò¥H¤Wµ{¦¡
80 ¦r¸`¥H¤º
¤£¤ä«ù¦Û©w¸q Discuz! ¥N½X

TOP

¦^´_ 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 : ·R¤£¬O­n¨D¹ï¤è¡A¦Ó¬O­n¥Ñ¦Û¨­ªº¥I¥X¡C
ªð¦^¦Cªí ¤W¤@¥DÃD