2017-09-25 69 views
0

Data EntryVBA代码练成

Chart after button execution

如在第一图所示,当我在星期六列中输入数据,同时如果数据大于小时数列的单元格颜色应变成绿色然后当我点击星期六按钮,如图2所示,图表应该显示像这样。它的好

现在,当我在星期日列输入数据为(图片1),小时列应刷新,单元格颜色应根据星期天列data.How可以做到这一点??。对应的图片2也应该刷新的时候我如果有搜索它在PIC单击按钮圣典2.

Thanks.Hope对于积极响应

Sub Button1_Click() 
Dim cht As ChartObject 
Dim i As Integer 
Dim vntValues As Variant 
Dim s As String 
Dim myseries As Series 

For Each cht In ActiveSheet.ChartObjects 
    For Each myseries In cht.Chart.SeriesCollection 

     If myseries.ChartType <> xlPie Then GoTo SkipNotPie 
     s = Split(myseries.Formula, ",")(2) 
     vntValues = myseries.Values 

     For i = 1 To UBound(vntValues) 
      myseries.Points(i).Interior.Color = range(s).Cells(i).Interior.Color 


     Next i 
SkipNotPie: 
    Next myseries 
Next cht 
End Sub 

回答

0

,你会发现下一个事件:

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("A1:C10") 

    If Not Application.Intersect(KeyCells, Range(Target.Address)) _ 
      Is Nothing Then 

     ' Display a message when one of the designated cells has been 
     ' changed. 
     ' Place your code here. 
     MsgBox "Cell " & Target.Address & " has changed." 

    End If 
End Sub 

ms网站。

根据您的意愿调整此示例。因此,用代码替换MsgBox行以更改按钮的背景颜色。