Excel 单动态图形代码
在excel中,我有4组属性,它们的租金数据是水平的,相应月份的租金数据在顶部水平。属性将垂直向下列出Excel 单动态图形代码,excel,vba,Excel,Vba,在excel中,我有4组属性,它们的租金数据是水平的,相应月份的租金数据在顶部水平。属性将垂直向下列出 June,'15 July,'15 Set 1 prop 1 $2,588.00 $2,588.00 prop 2 $1,835.00 $1,829.00 Set 2 prop 3 $2,647.00 $2,707.00 prop 4
June,'15 July,'15
Set 1
prop 1 $2,588.00 $2,588.00
prop 2 $1,835.00 $1,829.00
Set 2
prop 3 $2,647.00 $2,707.00
prop 4 $2,501.00 $2,526.00
我想为单个图形创建一个VBA代码,该图形从属性集1或属性集2选择要添加到图形中的数据。这取决于Excel中另一个单元格(下拉列表)的更改:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim KeyCells As Range
' The variable KeyCells contains the cells that will cause an alert when they are changed.
Set KeyCells = Range("D5")
If Not Application.Intersect(KeyCells, Range(Target.Address)) Is Nothing Then
'This is where I would place the graph code
End If
End Sub
实现这样一项任务的代码是什么——构建一个动态变化的图形
Private Sub Worksheet_Change(ByVal Target As Range)
Dim KeyCells As Range
' The variable KeyCells contains the cells that will cause an alert when they are changed.
Set KeyCells = Range("D5")
If Not Application.Intersect(KeyCells, Range(Target.Address)) Is Nothing Then
If Range("D5") = "Tremont" Then
Activesheet.Chartobjects("Single_Dynamic_Chart").FullSeriesCollection(1).XValues = Range(X_axis_values)
Activesheet.Chartobjects("Single_Dynamic_Chart").FullSeriesCollection(1).Name = "Tremont"
Activesheet.Chartobjects("Single_Dynamic_Chart").FullSeriesCollection(1).Values = Range(Y_axis_values)
'If a bar graph,
with Selection.Format.Fill
.Visible = msoTrue
.ForeColor.RGB= RGB(0,0,0)
.Transparency = 0
.Solid
End With
ElseIf Range("D5") = "Saybrook Pointe" Then
Activesheet.Chartobjects("Single_Dynamic_Chart").FullSeriesCollection(1).XValues = Range(X_axis_values)
Activesheet.Chartobjects("Single_Dynamic_Chart").FullSeriesCollection(1).Name = "Saybrook Pointe"
Activesheet.Chartobjects("Single_Dynamic_Chart").FullSeriesCollection(1).Values = Range(Y_axis_values)
'If a bar graph,
with Selection.Format.Fill
.Visible = msoTrue
.ForeColor.RGB= RGB(0,0,0)
.Transparency = 0
.Solid
End With
ElseIf Range("D5") = "21 Fitzsimons" Then
'Similarly like above cases, define the X-axis,the series name and the values.
ElseIf Range("D5") = "Mezzo" Then
'Similarly like above cases, define the X-axis,the series name and the values.
End If
End If
End Sub