多个私有子工作表_在同一个工作表中更改

时间:2016-03-13 12:56:22

标签: excel vba excel-vba

我在工作表中有以下子项,但我需要在同一工作表中针对不同的单元格/枢轴使用另外3个相同的子项。我怎么能这样做?

$user = user_load($GLOBALS['user']->uid);
$user->pass = 'the new password';
user_save((object) array('uid' => $user->uid), (array) $user);

1 个答案:

答案 0 :(得分:1)

我认为“相同”意味着他们都需要在worksheet_selectionchange中吗?由于您的代码当前不是b1:b2而退出,因此通过添加其他范围将代码更改为不在此时退出。您还应该在那里进行错误处理和启用事件。

    Private Sub Worksheet_SelectionChange(ByVal target As Range)
    On Error GoTo Bummer
    'This line stops the worksheet updating on every change, it only updates when cell
    'B1 or B2 is touched
    If Not Intersect(target, Range("B1:B2")) Is Nothing Then 'if not nothing
        Application.EnableEvents = False
        'Set the Variables to be used
        Dim pt As PivotTable
        Dim Field As PivotField
        Dim NewCat As String
        'Here you amend to suit your data
        Set pt = Worksheets("Daily Overall").PivotTables("DailyOverallSignups")
        Set Field = pt.PivotFields("Reg Year")
        NewCat = Worksheets("Daily Overall").Range("B1").Value
        'This updates and refreshes the PIVOT table
        With pt
            Field.ClearAllFilters
            Field.CurrentPage = NewCat
            pt.RefreshTable
        End With
    ElseIf Not Intersect(target, Range("c1:c2")) Is Nothing Then
        Application.EnableEvents = False
        MsgBox ("Foo")
    ElseIf Not Intersect(target, Range("d1:d2")) Is Nothing Then
        Application.EnableEvents = False
        MsgBox ("Bar")
    ElseIf Not Intersect(target, Range("e1:e2")) Is Nothing Then
        Application.EnableEvents = False
        MsgBox ("Hello World")
    Else
        Exit Sub
    End If

MovingOn:
    Application.EnableEvents = True
    Exit Sub
Bummer:
    MsgBox Err.Description
    Resume MovingOn
End Sub