0

このマクロは、別のシートのデータセットから取得しているダッシュボードに多数のグラフを入力するVBAを使用して開発しました。私が設定した方法は、希望するレポート期間に基づいて入力されるいくつかのテーブルがあります。テーブルは、チャートが関連情報のみを表示するように、=0のエントリをフィルタリングするように設定されています。

私はプログラミングの初心者であり、現在、マクロは機能しますが、時々ハングアップし、全体的にかなり不格好で非効率的です。このことを少しスムーズ/速く実行する簡単な方法はありますか?

ありがとう、

マイク

   Private Sub Calendar1_Click()
    ActiveCell.Value = CDbl(Calendar1.Value)
    ActiveCell.NumberFormat = "mm/dd/yyyy"
    Calendar1.Visible = False
End Sub

Private Sub Calendar2_Click()
    ActiveCell.Value = CDbl(Calendar2.Value)
    ActiveCell.NumberFormat = "mm/dd/yyyy"
    Calendar2.Visible = False
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

Sheets("Supervisor NC").Range("supervisor_nc").AutoFilter Field:=2

Sheets("Customer NC").Range("customer_nc").AutoFilter Field:=2

Sheets("Captain NC").Range("captain_nc").AutoFilter Field:=2

Sheets("Commodity NC").Range("commodity_nc").AutoFilter Field:=2

Sheets("Customer Specific Supervisor").Range("customer_spec_super").AutoFilter Field:=2

    If Target.Cells.Count > 1 Then Exit Sub

    If Not Application.Intersect(Range("a2"), Target) Is Nothing Then



        Calendar1.Left = Target.Left + Target.Width - Calendar1.Width
        Calendar1.Top = Target.Top + Target.Height
        Calendar1.Visible = True
        ' select Today's date in the Calendar
        Calendar1.Value = Date
    ElseIf Calendar1.Visible Then Calendar1.Visible = False
    End If

   If Target.Cells.Count > 1 Then Exit Sub

    If Not Application.Intersect(Range("b2"), Target) Is Nothing Then



        Calendar2.Left = Target.Left + Target.Width - Calendar2.Width
        Calendar2.Top = Target.Top + Target.Height
        Calendar2.Visible = True
        ' select Today's date in the Calendar
        Calendar2.Value = Date
    ElseIf Calendar2.Visible Then Calendar2.Visible = False
    End If

Sheets("Supervisor NC").Range("supervisor_nc").AutoFilter Field:=2, Criteria1:="<>"

Sheets("Customer NC").Range("customer_nc").AutoFilter Field:=2, Criteria1:="<>"

Sheets("Captain NC").Range("captain_nc").AutoFilter Field:=2, Criteria1:="<>"

Sheets("Commodity NC").Range("commodity_nc").AutoFilter Field:=2, Criteria1:="<>"

Sheets("Customer Specific Supervisor").Range("customer_spec_super").AutoFilter Field:=2, Criteria1:="<>"

Application.Calculation = xlCalculationAutomatic



End Sub
4

1 に答える 1

0

以下のコードを試してください:

Private Sub Calendar1_Click()
    ActiveCell.Value = CDbl(Calendar1.Value)
    ActiveCell.NumberFormat = "mm/dd/yyyy"
    Calendar1.Visible = False
End Sub

Private Sub Calendar2_Click()
    ActiveCell.Value = CDbl(Calendar2.Value)
    ActiveCell.NumberFormat = "mm/dd/yyyy"
    Calendar2.Visible = False
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    If Target.Cells.Count > 1 Then Exit Sub

    'if Target.Column = 1 and Target.Row = 1 then    you can also specify rows and cols here

    With Application
        .ScreenUpdating = False
        .EnableEvents = False
        .Calculation = xlCalculationManual
    End With

    Sheets("Supervisor NC").Range("supervisor_nc").AutoFilter Field:=2

    Sheets("Customer NC").Range("customer_nc").AutoFilter Field:=2

    Sheets("Captain NC").Range("captain_nc").AutoFilter Field:=2

    Sheets("Commodity NC").Range("commodity_nc").AutoFilter Field:=2

    Sheets("Customer Specific Supervisor").Range("customer_spec_super").AutoFilter Field:=2



    If Not Application.Intersect(Range("a2"), Target) Is Nothing Then

        Calendar1.Left = Target.Left + Target.Width - Calendar1.Width
        Calendar1.Top = Target.Top + Target.Height
        Calendar1.Visible = True
        ' select Today's date in the Calendar
        Calendar1.Value = Date
    ElseIf Calendar1.Visible Then
        Calendar1.Visible = False
    End If


    If Not Application.Intersect(Range("b2"), Target) Is Nothing Then
        Calendar2.Left = Target.Left + Target.Width - Calendar2.Width
        Calendar2.Top = Target.Top + Target.Height
        Calendar2.Visible = True
        ' select Today's date in the Calendar
        Calendar2.Value = Date
    ElseIf Calendar2.Visible Then
        Calendar2.Visible = False
    End If

    Sheets("Supervisor NC").Range("supervisor_nc").AutoFilter Field:=2, Criteria1:="<>"

    Sheets("Customer NC").Range("customer_nc").AutoFilter Field:=2, Criteria1:="<>"

    Sheets("Captain NC").Range("captain_nc").AutoFilter Field:=2, Criteria1:="<>"

    Sheets("Commodity NC").Range("commodity_nc").AutoFilter Field:=2, Criteria1:="<>"

    Sheets("Customer Specific Supervisor").Range("customer_spec_super").AutoFilter Field:=2, Criteria1:="<>"


    With Application
        .ScreenUpdating = True
        .EnableEvents = True
        .Calculation = xlCalculationAutomatic
    End With

End Sub
于 2013-03-12T18:03:30.400 に答える