CountIf不自动计算

时间:2017-01-20 13:58:19

标签: vba excel-vba countif excel

我的countif功能如果不自动计算 - 我错过了什么吗?

NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];

NSURLRequest *request = [[AFHTTPRequestSerializer serializer] requestWithMethod:@"POST" URLString:@"someURL" parameters:@{} error:nil];

NSURLSessionDataTask *dataTask = [manager dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
    if (error) {
        /* Network error*/
        NSLog(@"Error: %@", error);
    } else {
        NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
        switch (httpResponse.statusCode) {
            case 200:
                NSLog(@"Success")
                /* Code in case of success == Server returned True  */
            default:
            /* Code in case of no success  == Server returned False */
                NSLog(@"Error");
        }

    }
}];
[dataTask resume];

当我使用以下命令时,我必须手动点击它并按回车键以显示更新的答案

    Option Explicit

Function my3CountIfs(Rng1 As Range, Criteria1 As String, Rng2 As Range, Criteria2 As String, Rng3 As Range, Criteria3 As String) As Long

Dim ws As Worksheet

For Each ws In ThisWorkbook.Worksheets

    Select Case ws.Name
        Case "Summary-Sheet", "Notes", "Results", "Instructions", "Template"
            ' do nothing

        Case Else
             my3CountIfs = my3CountIfs + Application.CountIfs(ws.Range(Rng1.Address), Criteria1, ws.Range(Rng2.Address), Criteria2)

    End Select
Next ws

End Function

是的,我有excel设置为自动计算。

感谢您的帮助 - 今晚在这张excel表上发表演讲,发现它无法正常工作! - 哎呀!

1 个答案:

答案 0 :(得分:0)

正如评论中提到的cyboashu,您需要将Application.Volatile放在函数中。但正如Rik所说,这也可能导致性能问题。 This particular post及其答案与您的问题相关。

只是您可以选择的选项摘要:

Function xyz()
    Application.Volatile 'or Application.Volatile = True in later versions
    ...
End Function

或某些手动按键

  • F9 重新计算所有打开的工作簿中的所有工作表
  • Shift + F9 重新计算有效工作表
  • Ctrl + Alt + F9 重新计算所有打开的工作簿中的所有工作表(完全重新计算)
  • Shift + Ctrl + Alt + F9 重建依赖关系树并进行全面重新计算

或者对我有用的选项(因为我每次运行特定的宏时只需要重新计算UDF)就像使用SendKeys一样:

Sub xyz()
    ...
    'Recalculates all formulas by simulating keypresses for {ctrl}{alt}{shift}{F9}
    SendKeys "^%+{F9}"
    ...
End Sub

Here's the MSDN page for SendKeys