#NA错误复制/粘贴Excel In-cell函数

问题描述 投票:-1回答:1

当我手动复制并粘贴包含单元内自定义函数的单个单元格(在同一列中)时,我在Excel 2016中随机获得#N / A错误。

细胞A1,A3和A10含有相同的细胞内功能(工作正常)。

我想用单元格函数的值(结果)替换单元格A1,A3和A10。

我在每个单独的单元格上使用标准的复制和粘贴值操作,即不是范围选择。应该很容易吧?

复制/粘贴值可以在单元格A3上使用,但不在A1或A10上。

对于所有单元格,单元格格式化是相同的,即与提供#N / A错误的单元格一样有效。我在每个细胞上做同样的事情。

如果我在单元格A1和A10上重复操作,有时它会工作,有时则不会。

这令人沮丧,也是一个时间杀手。在决定工作之前,我不能尝试重复操作。

我应该采取哪些不同的想法?以下是单元格公式中引用的UDF代码:

Function example(Myrange As Range) As String


Dim regEx As New RegExp
Dim strPattern As String
Dim strInput As String
Dim strReplace As String

strPattern = "^(\d{6} )(- )(Smith)(\D*?)\s*(\d{4}\D)"

If strPattern <> "" Then
    strInput = Myrange.Value
    strReplace = "$1(ZT$5) $2$3 $5$4"

    With regEx
        .Global = True
        .MultiLine = True
        .IgnoreCase = False
        .Pattern = strPattern
    End With

    If regEx.Test(strInput) Then
        example = regEx.Replace(strInput, strReplace)

    Else
        example = Myrange.Value
    End If
End If
End Function
excel vba excel-vba
1个回答
0
投票

我将Excel中的公式计算选项从“自动”更改为“手动”,并且复制和粘贴值操作现在一致地工作。

© www.soinside.com 2019 - 2024. All rights reserved.