Excel 那么VBA中的Close-ISER函数不起作用了吗?

Excel 那么VBA中的Close-ISER函数不起作用了吗?,excel,vba,Excel,Vba,我非常接近我的解决方案,但我似乎有一个障碍。我复制了下面的代码。总之,我使用VLookup从另一个工作表中提取伪公式,用真实单元格引用替换伪“ZZZ”,然后将这些单元格值转换为最终公式。这一切都很好,除了输入伪公式的用户习惯于使用错误的公式,所以我需要一些错误检查。首先,我需要重命名任何不返回结果的VLookup值。其次,我需要重命名任何无效的最终公式(例如缺少括号)。以下是我目前掌握的情况: Public Sub VLookup() ActiveSheet.EnableCalcula

我非常接近我的解决方案,但我似乎有一个障碍。我复制了下面的代码。总之,我使用VLookup从另一个工作表中提取伪公式,用真实单元格引用替换伪“ZZZ”,然后将这些单元格值转换为最终公式。这一切都很好,除了输入伪公式的用户习惯于使用错误的公式,所以我需要一些错误检查。首先,我需要重命名任何不返回结果的VLookup值。其次,我需要重命名任何无效的最终公式(例如缺少括号)。以下是我目前掌握的情况:

Public Sub VLookup()

    ActiveSheet.EnableCalculation = True

'Define what our Rows are for the calculations
    Dim NumRecords As Long
    NumRecords = Workbooks("POVA Daily Reporter.xlsm").Worksheets("Paste Daily Data").Range("B" & Rows.Count).End(xlUp).Row
    Dim CellsForFormula As Range
    Set CellsForFormula = Workbooks("POVA Daily Reporter.xlsm").Worksheets("Paste Daily Data").Range("G2", "G" & NumRecords)
    Workbooks("POVA Daily Reporter.xlsm").Worksheets("Paste Daily Data").Select

'Now Insert the VLookup
    Dim WSLogic As Worksheet
    Dim WSData As Worksheet
    Set WSData = Workbooks("POVA Daily Reporter.xlsm").Worksheets("Paste Daily Data")
    Set WSLogic = Workbooks("POVA Daily Reporter.xlsm").Worksheets("Logic Statements")

'Write the Vlookup in the cell
    CellsForFormula(1, 1).Formula = _
        "=VLOOKUP('Paste Daily Data'!B2,'Logic Statements'!A:D,4,False)"
'Copy the Vlookup down
    CellsForFormula(1, 1).Copy _
        Destination:=Range(CellsForFormula(2, 1), CellsForFormula(NumRecords - 1, 1))
'Make sure the formulas actually calculate
    Workbooks("POVA Daily Reporter.xlsm").Worksheets("Paste Daily Data").UsedRange.Calculate

'Copy and Paste so we just keep the result of the Vlookup
    CellsForFormula.Copy
    CellsForFormula.PasteSpecial Paste:=xlPasteValues

'Now we can replace the "ZZZ" and "zzz" with the cell reference

    Application.EnableEvents = False
    Dim Cell As Variant
    On Error Resume Next

    For Each Cell In CellsForFormula
        If Cell.Value = "#N/A" Then
            Cell.Value = "Bill-to Not in POVA"
        'ElseIf Cell.Formula.IsErr = "=" & Cell.Value Then
            'Cell.Value = "Logic Code Incorrect"
        Else
            Cell.Formula = "=" & Cell.Value
            ActiveSheet.EnableCalculation = True
        End If
    Next Cell

    For Each Cell In CellsForFormula
        Call Cell.Replace("ZZZ", Cell.Offset(0, -4).Address)
        Cell.Application.WorksheetFunction = "="
        ActiveSheet.EnableCalculation = True
    Next Cell

    For Each Cell In CellsForFormula
        If Cell.Value = "#N/A" Then
            Cell.Value = "Bill-to Not in POVA"
            ActiveSheet.EnableCalculation = True
        End If
    Next Cell
    Application.EnableEvents = True
    Sheet.Calculate

End Sub
问题在于那些公式是无效的-因为“下一步继续”时出现错误,所以只需将它们放在一边:

AND(LEN($C$37)=10,ISNUMBER(VALUE($C$37))

任何帮助都将不胜感激

我相信您要找的是
.WorksheetFunction
而不是
.Function

例如,更改此选项:

For Each Cell In CellsForFormula
        If Cell.Value = "#N/A" Then
            Cell.Value = "Bill-to Not in POVA"
        ElseIf Cell.Formula.IsErr = "=" & Cell.Value Then
            'Cell.Value = "Logic Code Incorrect"
        Else
            Cell.Formula = "=" & Cell.Value
            ActiveSheet.EnableCalculation = True
        End If
    Next Cell
为此:

For Each Cell In CellsForFormula
        If Cell.Value = "#N/A" Then
            Cell.Value = "Bill-to Not in POVA"
        ElseIf Cell.WorksheetFormula.IsErr = "=" & Cell.Value Then
            'Cell.Value = "Logic Code Incorrect"
        Else
            Cell.Formula = "=" & Cell.Value
            ActiveSheet.EnableCalculation = True
        End If
    Next Cell

VBA中没有
ISNUMBER
。它应该是
IsNumeric
<代码>ISNUMBER用于工作表。此外,应小心使用
OERN
。这是一个很好的错误处理例程,但需要进行大量测试,以避免遗漏相关错误。我的意思是,有些错误你不想被忽略。