Application.ScreenUpdating не работает при обновлении / изменении диаграмм? - PullRequest
0 голосов
/ 17 января 2020

У меня есть лист с несколькими диаграммами с вертикальными полосами, представляющими статистические данные. Когда файл Excel открывается, он обновляет все диаграммы, удаляя их, а затем возвращая данные на место. (это необходимо, поскольку данные могли быть изменены ранее)

Макрос начинается с «Application.ScreenUpdating = False», а в конце (см. код) мы вызываем функции, обновляющие диаграммы. каждая функция начинается с Application.ScreenUpdating = false и заканчивается Application.ScreenUpdating = true ...

Я пытался удалить эти Application.ScreenUpdating, так как основная вызывающая функция уже получила Application.ScreenUpdating = T / F, но это ничего не меняет, мы видим, что все данные диаграмм удаляются и возвращаются по очереди ...

Этого не должно быть: - (

вот код:

Private Sub Workbook_Open()
'''When the file is opened

Application.ScreenUpdating = False 

'Putting back all macro buttons and comboboxes in the right place
'##############################################################################
Worksheets("Comparaison").ComboBox1.Left = 474
Worksheets("Comparaison").ComboBox1.Height = 25.5
Worksheets("Comparaison").ComboBox1.Width = 99
Worksheets("Comparaison").ComboBox1.Top = 64.5

'Etc Etc

'##############################################################################
Worksheets("Dealer_comparaison").ComboBox1.Left = 474
Worksheets("Dealer_comparaison").ComboBox1.Height = 25.5
Worksheets("Dealer_comparaison").ComboBox1.Width = 99
Worksheets("Dealer_comparaison").ComboBox1.Top = 69

'Etc etc

Worksheets("Dealer_comparaison").ComboBox1.Clear
Worksheets("Dealer_comparaison").ComboBox2.Clear
Worksheets("Dealer_comparaison").ComboBox3.Clear
Worksheets("Dealer_comparaison").ComboBox4.Clear
Worksheets("Dealer_comparaison").ComboBox5.Clear
Worksheets("Dealer_comparaison").ComboBox6.Clear

'##############################################################################
'"Data from" combo box
Worksheets("Dealer_detail").ComboBox1.Left = 474
Worksheets("Dealer_detail").ComboBox1.Height = 25.5
Worksheets("Dealer_detail").ComboBox1.Width = 99
Worksheets("Dealer_detail").ComboBox1.Top = 64.5

'Etc etc
'##############################################################################

'"Data from" combo box
Worksheets("Drv.Km-Evol").DrivenKmCombo.Left = 1.5
Worksheets("Drv.Km-Evol").DrivenKmCombo.Height = 21
Worksheets("Drv.Km-Evol").DrivenKmCombo.Width = 64.5
Worksheets("Drv.Km-Evol").DrivenKmCombo.Top = 62.25

'##############################################################################

'Filling the comboboxes with the years
For i = 1 To Sheets.Count 'Going through all the sheets
    If IsNumeric(Sheets(i).Name) Then 'Putting all year sheets in combobox
        Worksheets("Comparaison").ComboBox1.AddItem Sheets(i).Name
        Worksheets("Comparaison").ComboBox2.AddItem Sheets(i).Name

        Worksheets("Dealer_comparaison").ComboBox1.AddItem Sheets(i).Name
        Worksheets("Dealer_comparaison").ComboBox2.AddItem Sheets(i).Name

        Worksheets("Dealer_detail").ComboBox1.AddItem Sheets(i).Name
        Worksheets("Dealer_detail").ComboBox2.AddItem Sheets(i).Name

        Worksheets("Drv.Km-Evol").DrivenKmCombo.AddItem Sheets(i).Name
    End If
Next

'Filling the combobox with the Regions in Dealer_comparaison
i = 4
last_region = "test"
Do While Not IsEmpty(Worksheets("Dealer_comparaison").Range("BD" & i)) 'Going through all the regions
    If last_region <> Worksheets("Dealer_comparaison").Range("BD" & i).Value Then 'Region only counted once
        Worksheets("Dealer_comparaison").ComboBox7.AddItem Worksheets("Dealer_comparaison").Range("BD" & i).Value 'Adding the region
        Worksheets("Dealer_detail").ComboBox7.AddItem Worksheets("Dealer_comparaison").Range("BD" & i).Value 'Adding the region
        last_region = Worksheets("Dealer_comparaison").Range("BD" & i).Value 'Region already counted
    End If
    i = i + 1
Loop

'Filling the combobox with the dealers in Dealer_detail
J = 37
last_Dealer = "test"
Worksheets("Dealer_detail").DealerDisplayCombo.AddItem "*All*"
Worksheets("Dealer_detail").DealerDisplayCombo.Value = "*All*"
Do While Not IsEmpty(Worksheets("Dealer_detail").Range(Split(Cells(1, J).Address, "$")(1) & 3)) 'Going through all the dealers
    If last_Dealer <> Worksheets("Dealer_detail").Range(Split(Cells(1, J).Address, "$")(1) & 3).Value Then 'Region only counted once
        Worksheets("Dealer_detail").DealerDisplayCombo.AddItem Worksheets("Dealer_detail").Range(Split(Cells(1, J).Address, "$")(1) & 3).Value 'Adding the region
        last_Dealer = Worksheets("Dealer_detail").Range(Split(Cells(1, J).Address, "$")(1) & 3).Value 'Region already counted
    End If
    J = J + 1
Loop

'Filling the combobox with the min distances in every sheet
Worksheets("Comparaison").MinDistCombo.Value = 10
For MinDist = 0 To 200 Step 10
    Worksheets("Comparaison").MinDistCombo.AddItem MinDist 'Adding the region
    Worksheets("Dealer_comparaison").MinDistCombo.AddItem MinDist 'Adding the region
    Worksheets("Dealer_detail").MinDistCombo.AddItem MinDist 'Adding the region
Next


'update the data in case the years tabs have been changed
'this calls functions that update the data in the pages, but even before this, the screen is already showing the updates.
'moreover, each function called got a Application.ScreenUpdating = false at the beginning

'Call Functionthatdonteexist

Worksheets("Comparaison").Activate
Call Sheet1.ChangeComboBox1
Call Sheet1.ChangeComboBox2

Worksheets("Dealer_comparaison").Activate
Call Sheet2.ChangeComboBox1
Call Sheet2.ChangeComboBox2
Call Sheet2.ChangeComboRegion


Worksheets("Dealer_detail").Activate
Call Sheet6.ChangeComboBox1
Call Sheet6.ChangeComboBox2

Worksheets("Comparaison").Activate
Worksheets("Comparaison").Range("C2").Select

Application.ScreenUpdating = True   
End Sub

И вот одна из функций:

Я добавил Application.ScreenUpdating = false в начале (и true в конце курса) каждой из этих функций , но это ничего не изменило ... Я отозвал его, думая, что факт наличия «ложь, а затем истина» заставляет Excel обновлять экран каждый раз, но это ничего не изменило: (

Private Sub ComboBox1_Change()
'''Changing the first year value
Application.ScreenUpdating = False                                          'Stop the display of the events to gain a LOT of execution time
Call ChangeComboBox1
Application.ScreenUpdating = True                                          'Stop the display of the events to gain a LOT of execution time
End Sub

Public Function ChangeComboBox1()
'''Changing the first year value


'Worksheets("Comparaison").Activate

If ComboBox1.Value > ComboBox2.Value Then 'We want to keep the more ancient in the first combobox
    MsgBox "Please select a year value lower than the the other selected"
    ComboBox1.Value = ComboBox2.Value
Else
    Worksheets("Comparaison").Range("B10").Value = ComboBox1.Value 'Changing the year in the first year box

    count_deliver = 0 'Counting number of delivered cars
    'Computing number of cars in the corresponding year
    nb_line = 3
    Do While Not IsEmpty(Worksheets(ComboBox1.Value).Range("A" & nb_line))
        If Worksheets(ComboBox1.Value).Range("D" & nb_line).Value <> "N/A" Then
            If Year(Worksheets(ComboBox1.Value).Range("D" & nb_line).Value) = CInt(ComboBox1.Value) Then 'Year corresponding to the year of analysis
                count_deliver = count_deliver + 1
            End If
        End If
        nb_line = nb_line + 1
    Loop

    Worksheets("Comparaison").Range("I10").Value = nb_line - 3 'Number of cars in the first year
    Worksheets("Comparaison").Range("N10").Value = count_deliver 'Number of cars in the first year

    Call Format_charts.Update_colors 'Changing colors based on region
    Call Format_charts.Update_prevision 'Displaying previsions if not a full year of analysis
    Call Format_charts.Update_axis 'Changing axis scales based on maximum values
End If

'Bug protection
Worksheets("Comparaison").ComboBox1.Left = 474
Worksheets("Comparaison").ComboBox1.Height = 25.5
Worksheets("Comparaison").ComboBox1.Width = 99
Worksheets("Comparaison").ComboBox1.Top = 64.5

End Function

Как заставить это работать должным образом? Я почти уверен, что потерял много времени с этими обновлениями экрана, которые не должны происходить.

Я добавил

Спасибо заранее! * 102 1 *

...