Excel 宏更改数据验证时重新计算

Excel 宏更改数据验证时重新计算,excel,vba,Excel,Vba,我有一系列的数据验证字段,我使用宏来来回切换 当宏设置数据验证字段的值时,工作簿将无法通过更新工作表来跟上 我已经检查过计算是否设置为自动。我尝试在每次选择后重新计算工作表 Sub generate_indications() ThisWorkbook.Worksheets("Filing Indication Selections").Range("H:K").ClearContents Application.ScreenUpdating = True Dim fil

我有一系列的数据验证字段,我使用宏来来回切换

当宏设置数据验证字段的值时,工作簿将无法通过更新工作表来跟上

我已经检查过计算是否设置为自动。我尝试在每次选择后重新计算工作表

Sub generate_indications()
    ThisWorkbook.Worksheets("Filing Indication Selections").Range("H:K").ClearContents
    Application.ScreenUpdating = True
    Dim filing_sheet As Worksheet
    Dim selection_sheet As Worksheet
    Dim indication As Double
    Set filing_sheet = ThisWorkbook.Worksheets("Filing Indication")
    Set selection_sheet = ThisWorkbook.Worksheets("Filing Indication Selections")
    For Each ind_option In selection_sheet.Range("A:A")
        'filing_sheet.EnableCalculation = False
        If selection_sheet.Cells(ind_option.Row, 1) = "" Then
            'filing_sheet.EnableCalculation = True
            Exit Sub
        End If
        With filing_sheet
            .Range("A7").Value = selection_sheet.Cells(ind_option.Row, 1).Value 'Capped/Uncapped
            If selection_sheet.Cells(ind_option.Row, 2).Value = "N/A" Then
                'Set to 250K by default, though this won't affect the calculation
                .Range("A6").Value = "250K"
            Else
                .Range("A6").Value = selection_sheet.Cells(ind_option.Row, 2).Value '250K or 100K
            End If
            .Range("A8").Value = selection_sheet.Cells(ind_option.Row, 3).Value 'Paid/Incurred
            If selection_sheet.Cells(ind_option.Row, 4).Value = "CW Loss Trend" Then
                'Select the CW version
                .Range("A9").Value = selection_sheet.Cells(ind_option.Row, 4).Value
            Else
                .Range("A9").Value = .Range("L7").Value & " Loss Trend" 'Select the State Loss Trend
            End If
            .Range("A10").Value = selection_sheet.Cells(ind_option.Row, 5).Value 'Bureau/Farmers LDF
            If selection_sheet.Cells(ind_option.Row, 5).Value = "Bureau LDF" Then
                'Choose option for 2yr vs 5yr
                If Left(selection_sheet.Cells(ind_option.Row, 6).Value, 1) = 2 Then
                    .Range("A18").Value = "2 Yr Bureau"
                Else
                    .Range("A18").Value = "5 Yr Bureau"
                End If

            Else
                'Choose option 1-5 yr
                If Left(selection_sheet.Cells(ind_option.Row, 6).Value, 1) = 1 Then
                    .Range("A12").Value = "1 Yr Ave"
                ElseIf Left(selection_sheet.Cells(ind_option.Row, 6).Value, 1) = 2 Then
                    .Range("A12").Value = "2 Yr Ave"
                ElseIf Left(selection_sheet.Cells(ind_option.Row, 6).Value, 1) = 3 Then
                    .Range("A12").Value = "3 Yr Ave"
                ElseIf Left(selection_sheet.Cells(ind_option.Row, 6).Value, 1) = 4 Then
                    .Range("A12").Value = "4 Yr Ave"
                ElseIf Left(selection_sheet.Cells(ind_option.Row, 6).Value, 1) = 4 Then
                    .Range("A12").Value = "5 Yr Ave"
                Else
                    .Range("A12").Value = "Default"
                End If
            End If
            If selection_sheet.Cells(ind_option.Row, 7).Value = "CW Compliment" Then
                .Range("A11").Value = "CW LT Compliment"
            ElseIf selection_sheet.Cells(ind_option.Row, 7).Value = "Standard" Then
                .Range("A11").Value = "Standard Compliment"
            Else
                .Range("A11").Value = .Range("L7").Value & " LT Compliment"
            End If
            'filing_sheet.EnableCalculation = True
            .Calculate
            indication = .Range("I41").Value
            complement = .Range("I40").Value
            credibility = .Range("I39").Value
            preZ = .Range("I38").Value
        End With
        selection_sheet.Cells(ind_option.Row, 8).Value = indication
        selection_sheet.Cells(ind_option.Row, 9).Value = complement
        selection_sheet.Cells(ind_option.Row, 10).Value = credibility
        selection_sheet.Cells(ind_option.Row, 11).Value = preZ

    Next ind_option
End Sub

与类似问题的链接可能有帮助,也可能没有


我没有看到您在代码中定义活动工作表,或者在每个活动工作表中循环进行计算的循环

不确定使用.EnableCalculation尝试实现什么-尝试使用Application.Calculation=xlAutomatic。