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

[µo°Ý] ¦³ÃöexcelVBA¹Ïªíªº°ÝÃD

[µo°Ý] ¦³ÃöexcelVBA¹Ïªíªº°ÝÃD

¦U¦ì¦U¦ì~
¤£¦n·N«ä¡A§Ú²{¦b¦A¼gVBA¹Ïªí¡A­n°µªÑ¥«K½u¹Ï¡A
­n¦b¤@±i¹Ïªí¤W©ñ¤WK´Î©M²¾°Ê¥­§¡½u¡A¨Ã¦X¨Ö¹Ïªí©ñ¤W¦¨¥æ¶q¡A
¦ý¥Ø«e³o¼Ëªºµ{¦¡¦b2003ªºª©¥»¡AÅã¥Ü¥X¨Ó«Ü¥¿±`¡A
¥i¬O·í¥Î2007®É¡A¥Ñ©ó°Æ§@¼Ð¬O¥H¦¨¥æ¶q¬°¥D¡A
µM«á²¾°Ê¥­§¡½u¤]¥H°Æ§@¼Ð¬°¥D¡A
·|¾É­P²¾°Ê¥­§¡½u³QÀ½¦b©³¤U¬Ý¤£¨£= =
¦³¨S¦³¿ìªk¡AÅý²¾°Ê¥­§¡½u¤]©ñ¦b¥D®y¼Ð¶b
¤£·|¨ü¨ì¦¨¥æ¶q¼vÅT¡A
«ô°U¦U¦ìÀ°§Ú·Q·Q¡A¯uªº«Ü«æ~³Â·Ð¤F ÁÂÁÂ:'(

¦³»Ý­nµ{¦¡½X §Ú¥i¥Hªþ¤W ÁÂÁÂ))

TOP

¦^´_ 2# lin_6219
¥¼ªþ¤WÀɮסA¦U¦ì¤j¤j¦p¦ó´ú¸Õ§A©Ò¿×ªº°ÝÃD¡C

TOP

¦^´_ 3# c_c_lai
©êºp©êºp~§Ú¬O·s¤â¤]²Ä¤@¦¸µo°Ý
³o¸Ìªþ¤WÀÉ®×
½Ð¤j®aÀ°À°§Ú¡AÁÂÁÂ:))

K½u¦¨¥æ¶q.rar (23.04 KB)

TOP

¦^´_ 4# lin_6219
¸Õ¸Õ¬Ý¡I
  1. Sub KChartWithVolume()          '  K ½u¹Ï »P ¦¨¥æ¶q¹Ï ©ñ¦b¦P¤@¹Ïªí
  2.     Dim nRow As Integer, ChtObj As ChartObject
  3.     Dim i As Integer, j As Integer
  4.     Dim myMax, myMin, GapNr As Integer
  5.    
  6.     On Error Resume Next
  7.    
  8.     Worksheets("¥Dµe­±").ChartObjects.Delete
  9.     nRow = Worksheets("ø¹Ï¸ê®Æ").Range("A65536").End(xlUp).Row
  10.             
  11.     With Worksheets("ø¹Ï¸ê®Æ")                  '  ³]©w¥D®y¼Ð¶b³Ì¤j¤Î³Ì¤p­È
  12.         myMax = Application.Max(.Range("C2:C" & CStr(nRow)))
  13.         myMin = Application.Min(.Range("D2:D" & CStr(nRow)))
  14.         myMin = myMin - (myMax - myMin)
  15.     End With
  16.    
  17.     ' Set ChtObj = Worksheets("¥Dµe­±").ChartObjects.Add(1, 1, 450, 250)
  18.     Set ChtObj = Worksheets("¥Dµe­±").ChartObjects.Add(1, 1, 490, 280)
  19.    
  20.     With ChtObj.Chart
  21.         ' .SetSourceData Worksheets("ø¹Ï¸ê®Æ").Range("A2:E" & CStr(nRow))
  22.         .SetSourceData Source:=Range("ø¹Ï¸ê®Æ!$A$2:ø¹Ï¸ê®Æ!$E$" & CStr(nRow))
  23.         .ChartType = xlStockOHLC
  24.         .HasTitle = True
  25.         .ChartTitle.Characters.Text = "K½u»P¦¨¥æ¶q¹Ï"
  26.    
  27.         With .ChartGroups(1)
  28.             .HasUpDownBars = True
  29.             .UpBars.Interior.ColorIndex = 3
  30.             .DownBars.Interior.ColorIndex = 1
  31.             .GapWidth = 10
  32.         End With
  33.         
  34.         .SeriesCollection(1).Name = ""    ' ¶}½L»ù
  35.         .SeriesCollection(2).Name = ""    ' ³Ì°ª»ù
  36.         .SeriesCollection(3).Name = ""    ' ³Ì§C»ù
  37.         .SeriesCollection(4).Name = ""    ' ¦¬½L»ù (¦¨¥æ»ù)
  38.         
  39.         With .Axes(xlValue)
  40.             .MaximumScale = Round(myMax, 2)
  41.             .MinimumScale = Round(myMin, 2)
  42.             '  .MaximumScale = myMax
  43.             '  .MinimumScale = myMin
  44.             .MajorUnit = 0.5                        ' ¹Ïªí¥ª°¼¼Æ¦C¤§¶¡¶Z­È³]©w
  45.         End With
  46.             
  47.         '  .SeriesCollection.Add Worksheets("ø¹Ï¸ê®Æ").Range("G1:G" & CStr(nRow))
  48.         .SeriesCollection.Add Source:=Range("ø¹Ï¸ê®Æ!$G$1:ø¹Ï¸ê®Æ!$G$" & CStr(nRow))
  49.         With .SeriesCollection(5)
  50.             .AxisGroup = 1
  51.             '  .ChartType = xlXYScatterLinesNoMarkers
  52.             .ChartType = xlLines
  53.             .Name = "=ø¹Ï¸ê®Æ!$G$1"    '  ²¾°Ê¥­§¡½u
  54.             .Border.ColorIndex = 7
  55.         End With
  56.         
  57.         '  .SeriesCollection.NewSeries       '  ·s¼W¦¨¥æ¶q¼Æ¦C
  58.         .SeriesCollection.Add Source:=Range("ø¹Ï¸ê®Æ!$F$1:ø¹Ï¸ê®Æ!$F$" & CStr(nRow))
  59.         With .SeriesCollection(6)
  60.             .AxisGroup = 2                   '  ³]¬°°Æ®y¼Ð¶b
  61.             '  .Values = Worksheets("ø¹Ï¸ê®Æ").Range("F2:F" & CStr(nRow))
  62.             .ChartType = xlColumnClustered
  63.             .Name = "¦¨¥æ¶q"
  64.             .Interior.ColorIndex = 17
  65.         End With
  66.         
  67.         With Worksheets("ø¹Ï¸ê®Æ")                      '  ­pºâ°Æ®y¼Ð¶b³Ì¤j¤Î³Ì¤p­È
  68.             myMax = Application.Max(.Range("F2:F" & CStr(nRow)))
  69.             myMax = myMax * 2
  70.             myMin = 0.01
  71.         End With
  72.         
  73.         With .Axes(xlValue, xlSecondary)      '  ³]©w°Æ®y¼Ð¶b³Ì¤j¤Î³Ì¤p­È
  74.             .MaximumScale = Round(myMax, 0)
  75.             .MinimumScale = Round(myMin, 0)
  76.         End With
  77.         
  78.         With .PlotArea                         '  ½Õ¾ãø¹Ï°Ï°ì¤j¤p»P¦ì¸m
  79.             .Top = .Top - 2
  80.             .Height = .Height + 10
  81.             .Width = .Width + 75
  82.         End With
  83.         
  84.         .PlotArea.Select                        ' ±N¹ÏªíªºÃ¸¹Ï°Ï®æ½u¦Ç¶ÂÃC¦â­×§ï¦¨²H«C¦â¡B¥H¤Îªí®æ¹ê½u§ï¥Hµê½uªí¥Ü
  85.         .Axes(xlValue).MajorGridlines.Select
  86.         With Selection.Format.Line
  87.             .Visible = msoTrue
  88.             .ForeColor.ObjectThemeColor = msoThemeColorAccent1
  89.             .ForeColor.TintAndShade = 0
  90.             .ForeColor.Brightness = 0.8000000119
  91.             .Transparency = 0
  92.             .Weight = 0.25
  93.             .DashStyle = msoLineSysDash
  94.         End With
  95.         
  96.         With .Legend
  97.             .Position = xlLegendPositionTop
  98.             .Top = .Top - 8
  99.             .Border.ColorIndex = 57
  100.             .Border.Weight = xlThin
  101.             .Border.LineStyle = xlContinuous
  102.             .Interior.ColorIndex = xlNone
  103.         End With
  104.     End With
  105.     Worksheets("¥Dµe­±").[A1].Select
  106. End Sub
½Æ»s¥N½X

TOP

¦^´_ 4# lin_6219
ªþ¤W¹Ïªí¦@°Ñ¦Ò¡C

TOP

¦^´_ 4# lin_6219
ªÑ²¼¬Wª¬¹Ï¦n¹³»P¨ä¥¦¹ÏªíµLªk¦@³B¦b¦P¤@¥D¶b¤W¡C

TOP

¦^´_ 7# c_c_lai
¦n³á¡A«D±`«D±`·PÁ§A:)))))
¥Ø«e¦n¹³¯uªº¤£¯à§âK½u©M²¾°Ê¥­§¡½uÁÙ¦³¦¨¥æ¶q¤@°_©ñ¦b¦P¤@±i¹Ï¤W¡A
¾Ç®Õªº¦Ñ®v¤]§ä¤£¨ì¸Ñ¨Mªº¿ìªk¡A
¦A¦¸·PÁ§AªºÀ°¦£¡AÁÂÁ§A¡C:)

TOP

¦^´_ 8# lin_6219
¤@¯ë§Ú¬O±N¦¨¥æ¶q(°Æ®y¼Ð¶b)»PªÑ²¼¬Wª¬¹Ï(¥D®y¼Ð¶b)¤À¶}³B­ù¡A
¥ç§Y¥D®y¼Ð¶b«ü¦s¦bªÑ²¼¬Wª¬¹Ï¡A¨ä¥L§¡Âk°Æ®y¼Ð¶bÂkÃþ¡C
¦p¹Ï¡G


TOP

¦^´_ 8# lin_6219
§Ú±N§A´£¨Ñªºµ{¦¡½Xµyµy­×§ï¤F¤@¨Ç¡A
²¼ä¤F¤@¨Ç¨Ï¥Î¤§»yªk¡A®Ä¯q©Ê¥ç·|§ï¨}¡C
¦p¹Ï¡G (¤W¹Ï¬O­ì¥»µ{¦¡ªº°õ¦æµ²ªG¡A¤U¹Ï¬O¸g¹L­×¹¢ªº)
  1. Sub KChartWithVolume3()                         '  K½u¹Ï»P¦¨¥æ¶q¹Ï©ñ¦b¦P¤@¹Ïªí
  2.     Dim nRow As Integer, ChtObj As ChartObject
  3.     Dim i As Integer, j As Integer
  4.     Dim myMax, myMin, GapNr As Integer
  5.    
  6.     On Error Resume Next
  7.   
  8.     Worksheets("¥Dµe­±").ChartObjects.Delete
  9.     nRow = Worksheets("ø¹Ï¸ê®Æ").Range("A65536").End(xlUp).Row
  10.     Set ChtObj = Worksheets("¥Dµe­±").ChartObjects.Add(1, 1, 450, 250)
  11.    
  12.     With ChtObj.Chart
  13.         .SetSourceData Worksheets("ø¹Ï¸ê®Æ").Range("B2:E" & CStr(nRow))
  14.         .ChartType = xlStockOHLC
  15.         .HasTitle = True
  16.         .ChartTitle.Characters.Text = "K½u»P¦¨¥æ¶q¹Ï"
  17.         .SeriesCollection.Add Worksheets("ø¹Ï¸ê®Æ").Range("G1:G" & CStr(nRow))
  18.         
  19.         With .SeriesCollection(5)
  20.             .ChartType = xlXYScatterLinesNoMarkers
  21.             '  .ChartType = xlLine
  22.             .Border.ColorIndex = 7
  23.             .AxisGroup = xlPrimary
  24.             .Name = "=ø¹Ï¸ê®Æ!$G$1"
  25.         End With
  26.    
  27.         With .ChartGroups(1)
  28.             .AxisGroup = xlPrimary
  29.             .HasUpDownBars = True
  30.             .UpBars.Interior.ColorIndex = 3
  31.             .DownBars.Interior.ColorIndex = 1
  32.             .GapWidth = 10
  33.         End With
  34.         
  35.         With Worksheets("ø¹Ï¸ê®Æ")              '  ³]©w¥D®y¼Ð¶b³Ì¤j¤Î³Ì¤p­È
  36.             myMax = Application.Max(.Range("C2:C" & CStr(nRow)))
  37.             myMin = Application.Min(.Range("D2:D" & CStr(nRow)))
  38.             myMin = myMin - (myMax - myMin)
  39.         End With
  40.         
  41.         With .Axes(xlValue)
  42.             .MaximumScale = Round(myMax, 2)
  43.             .MinimumScale = Round(myMin, 2)
  44.         End With
  45.         
  46.         .SeriesCollection.NewSeries              '  ·s¼W¦¨¥æ¶q¼Æ¦C
  47.         With .SeriesCollection(6)
  48.             .Values = Worksheets("ø¹Ï¸ê®Æ").Range("F2:F" & CStr(nRow))
  49.             .ChartType = xlColumnClustered
  50.             .Name = "¦¨¥æ¶q"
  51.             .Interior.ColorIndex = 17
  52.             .AxisGroup = xlSecondary             '  ³]¬°°Æ®y¼Ð¶b
  53.         End With
  54.         
  55.         With Worksheets("ø¹Ï¸ê®Æ")              '  ­pºâ°Æ®y¼Ð¶b³Ì¤j¤Î³Ì¤p­È
  56.             myMax = Application.Max(.Range("F2:F" & CStr(nRow)))
  57.             myMax = myMax * 2
  58.             myMin = 0.01
  59.         End With
  60.         
  61.         With .Axes(xlValue, xlSecondary)         '  ³]©w°Æ®y¼Ð¶b³Ì¤j¤Î³Ì¤p­È
  62.             .MaximumScale = Round(myMax, 0)
  63.             .MinimumScale = Round(myMin, 0)
  64.         End With
  65.         
  66.          With .Axes(xlCategory)                               '  X®y¼Ð¶b (®É¶¡¶b)
  67.              .CategoryType = xlCategoryScale
  68.              .TickLabelSpacing = 3                            '  ¼Ð¥Ü¶¡¶Z
  69.              .TickLabels.NumberFormatLocal = "yyyy/m/d"
  70.              .TickLabels.Font.ColorIndex = 5                  '  Blue Color
  71.         End With
  72.         
  73.         With .Legend                                          '  §R°£¤£¥²­nªº¹Ï¨Ò
  74.             .LegendEntries(2).Delete
  75.             .LegendEntries(2).Delete
  76.             .LegendEntries(2).Delete
  77.             .LegendEntries(2).Delete
  78.             .Top = .Parent.ChartTitle.Top - 5
  79.         End With
  80.         
  81.         With .PlotArea                                        '  ½Õ¾ãø¹Ï°Ï°ì¤j¤p»P¦ì¸m
  82.             .Top = .Top - 10
  83.             .Height = .Height + 10
  84.             .Width = .Width + 75
  85.         End With
  86.         
  87.         .PlotArea.Select    '  ±N¹ÏªíªºÃ¸¹Ï°Ï®æ½u¦Ç¶ÂÃC¦â­×§ï¦¨²H«C¦â¡B¥H¤Îªí®æ¹ê½u§ï¥Hµê½uªí¥Ü
  88.         .Axes(xlValue).MajorGridlines.Select
  89.         With Selection.Format.Line
  90.             .Visible = msoTrue
  91.             .ForeColor.ObjectThemeColor = msoThemeColorAccent1
  92.             .ForeColor.TintAndShade = 0
  93.             .ForeColor.Brightness = 0.8000000119
  94.             .Transparency = 0
  95.             .Weight = 0.25
  96.             .DashStyle = msoLineSysDash
  97.         End With
  98.     End With
  99.     Worksheets("¥Dµe­±").[A1].Select
  100. End Sub
½Æ»s¥N½X

TOP

        ÀR«ä¦Û¦b : ¨C¤ÑµL©Ò¨Æ¨Æ¡A¬O¤H¥Íªº®ø¶OªÌ¡A¿n·¥¡B¦³¥Î¤~¬O¤H¥Íªº³Ð³yªÌ¡C
ªð¦^¦Cªí ¤W¤@¥DÃD