2017-09-25 60 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行以更改按鈕的背景顏色。