UDF不以VBA代码计算

我有一个UDF返回一个文本取决于每一行的时间和date。

这个UDF公式被放置在X2中,当我运行数据更新代码来replace表单中的所有数据时,我使用X2:Y和LastRow的填充。
我的计划是在UDF完成后过滤数据并删除不需要的数据。
因为Excel过滤时会重新计算数据,所以我认为我可以复制 – >粘贴值以确保UDF不会再次运行。
完整的代码如下,但“有趣”的部分是在''''''

 Sub importera() Dim mainWB As Workbook Dim srcWB As Workbook Set mainWB = ThisWorkbook 'Application.ScreenUpdating = False Sheets("XCFIL").Activate LastRow = Cells(Rows.Count, "A").End(xlUp).Row Range("A3:Y" & LastRow).ClearContents Range("A2:W2").ClearContents Workbooks.Open Filename:="C:\Textfiler\XCFIL.TXT" Range("A:A").TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _ TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _ Semicolon:=True, Comma:=False, Space:=False, Other:=False, FieldInfo _ :=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), _ Array(7, 1), Array(8, 1)), TrailingMinusNumbers:=True Set srcWB = ActiveWorkbook ActiveWorkbook.Sheets(1).Range("A2:W" & ActiveSheet.UsedRange.Rows.Count).Copy ThisWorkbook.Activate ActiveSheet.Paste Destination:=Worksheets("XCFIL").Range("A2") Application.DisplayAlerts = False srcWB.Close Application.DisplayAlerts = True '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' LastRow = Cells(Rows.Count, "A").End(xlUp).Row Range("X2:Y" & LastRow).FillDown ' To make sure the UDF does not run again turn off calculations Application.Calculation = xlManual Range("X3:Y" & LastRow).Copy Range("X3").PasteSpecial xlPasteValues Application.Calculation = xlAutomatic ' Turn on calculations again when formulas is replaced with values ActiveSheet.Range("A1:Y" & LastRow).AutoFilter Field:=24, Criteria1:="0" With ActiveSheet.AutoFilter.Range .Offset(1).Resize(.Rows.Count - 1).EntireRow.Delete End With '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ThisWorkbook.Activate Worksheets("Resultat").PivotTables("Pivottabell3").PivotCache.Refresh Worksheets("Resultat").PivotTables("Pivottabell2").PivotCache.Refresh Worksheets("Resultat").PivotTables("Pivottabell1").PivotCache.Refresh End Sub 

问题是FillDown不会在所有单元上运行UDF。
代码完成FillDown后,计算开始在状态栏(?)中计数,当达到100%时,还没有完成。 它计算的不到50%,其余的值是#VALUE! 错误。 (如果我停止数据更新代码,UDF运行并芬兰语正确与没有值错误)

但这意味着我需要一些方法来检测所有UDF单元何时完成,然后closures计算并复制粘贴。
有关如何更改代码的任何build议?

我build议你在适当的时候在你的VBA代码中做相关的计算,然后直接在工作表中input这些结果。 无需担心UDF的完成。 编码应该既简单又快捷。