简体   繁体   中英

2 private sub worksheet_change

I have the following bit of code:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim C As Range, D As Range, v
Set C = Range("C1:C20")
Set D = Range("D1:D20")
v = Target.Value

If Intersect(Union(C, D), Target) Is Nothing Then Exit Sub

Application.EnableEvents = False
    If Intersect(Target, D) Is Nothing Then
        Target.Offset(0, 1).Value = 12 * v
    Else
        Target.Offset(0, -1).Value = v / 12
    End If
Application.EnableEvents = True

Dim H As Range, I As Range, v2
Set H = Range("H8:H11")
Set I = Range("I8:I11")
v2 = Target.Value

If Intersect(Union(H, I), Target) Is Nothing Then Exit Sub

Application.EnableEvents = False
    If Intersect(Target, I) Is Nothing Then
        Target.Offset(0, 1).Value = 12 * v2
    Else
        Target.Offset(0, -1).Value = v2 / 12
    End If
Application.EnableEvents = True

'Sheets("Költségvetés").AutoFilter.ApplyFilter

' first remove filter
ActiveSheet.Range("$F$54:$$67").AutoFilter Field:=2
' then apply it again
ActiveSheet.Range("$F$54:$$67").AutoFilter Field:=2, Criteria1:="<>0"

End Sub

I wanna have a pie chart that updates whenever a new value is entered, and doesn't show data labels to 0 valued items.

Thanks!

If Intersect(Union(C, D), Target) Is Nothing Then Exit Sub

is preventing the second section from running. Change to

Set all your ranges etc

If Not Intersect(Union(C, D), Target) Is Nothing Then 
    '... first section
ElseIf Not Intersect(Union(H, I), Target) Is Nothing Then
    '... second section
End If

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM