按钮的vba代码单击ms excel

时间:2017-09-25 09:19:31

标签: excel vba excel-vba

Data Entry

Chart after button execution

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

现在当我在星期日列中输入数据时(图1),小时列应该刷新,单元格颜色应该根据周日列数据来进行。我怎么能这样做?相应的图片2也应当刷新点击图2中的sundy按钮。

谢谢。希望积极回应

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

1 个答案:

答案 0 :(得分: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-line以更改按钮的背景颜色。

相关问题