Skip to content

Instantly share code, notes, and snippets.

@TanisukeGoro
Last active December 26, 2017 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TanisukeGoro/6910e6d37e3b7f8e5f8dd96227312ea2 to your computer and use it in GitHub Desktop.
Save TanisukeGoro/6910e6d37e3b7f8e5f8dd96227312ea2 to your computer and use it in GitHub Desktop.
Option Explicit
Sub Scatter3Dplot()
Dim Cobj As ChartObject
Dim Sh As Worksheet
Set Sh = ActiveSheet
Dim StartR As Long, EndR As Long
Dim CollarScaleCol As Long, SeriesName As Long, XSeries As Long, YSeries As Long
Dim MarkerCollar As Long
Dim i As Long
Dim c, r, g, b
Dim NSeries As Long
'アクティブなグラフのオブジェクトを追加する。
'ActiveChartプロパティは、Chartオブジェクトを返すので、
'ChartオブジェクトのParentプロパティで、ChartObjectオブジェクトを取得して、オブジェクト変数にセット
Set Cobj = ActiveChart.Parent
SettingUI.Show
'ユーザーフォームからの値取得
'値のエラー処理
With SettingUI
If .CSC.Value = "" Or .SNC.Value = "" Or _
.XS.Value = "" Or .YS.Value = "" Or .SR.Value = "" Or .ER.Value = "" Then
MsgBox "Value Error. Check the value.", vbExclamation, "Error"
End
End If
End With
CollarScaleCol = SettingUI.CSC.Value
SeriesName = SettingUI.SNC.Value
XSeries = SettingUI.XS.Value
YSeries = SettingUI.YS.Value
StartR = SettingUI.SR.Value
EndR = SettingUI.ER.Value
If EndR < StartR Then
MsgBox "Value Error, End Row's value is larger than Star Row.", vbExclamation, "Error"
End
End If
For i = StartR To EndR
With Cobj.Chart
'系列の新規追加
.SeriesCollection.NewSeries
'系列数の取得
NSeries = .SeriesCollection.Count
End With
With Cobj.Chart.FullSeriesCollection(NSeries)
'系列名, X, Yのセット
'セルを指定するだけでいいらしい。まじか。
.Name = Sh.Cells(i, SeriesName)
.XValues = Sh.Cells(i, XSeries)
.Values = Sh.Cells(i, YSeries)
'散布図に設定, マーカーの種類, サイズの指定
.ChartType = xlXYScatter
.MarkerStyle = 8
.MarkerSize = 7
'マーカの色取得(カラーマップ), マーカーの色設定
c = Right("000000" & Hex(Cells(i, CollarScaleCol).Interior.Color), 6)
r = Val("&H" & Right(c, 2))
g = Val("&H" & Mid(c, 3, 2))
b = Val("&H" & Left(c, 2))
.Format.Fill.Visible = msoTrue
.Format.Fill.ForeColor.RGB = RGB(r, g, b)
'マーカーの色なし
.MarkerForegroundColorIndex = xlColorIndexNone
End With
Next i
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment