Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 从单元格中提取自定义格式_Excel_Vba - Fatal编程技术网

Excel 从单元格中提取自定义格式

Excel 从单元格中提取自定义格式,excel,vba,Excel,Vba,我有如下自定义单元格格式: 0.0%“(1L)”;(0.0%“(1L)”;——;@) 我正试图将1L提取到一个细胞中 还有另一个例子,它看起来像 0.0%“(2L)”;(0.0%“(2L)”;——;@) 我需要确定它是2L还是1L。一个简单的自定义项可能: Function WhichOne(ByVal rng As Range) As String Application.Volatile If InStr(rng.NumberFormat, "1L") > 0 Then

我有如下自定义单元格格式:

0.0%“(1L)”;(0.0%“(1L)”;——;@)

我正试图将1L提取到一个细胞中

还有另一个例子,它看起来像

0.0%“(2L)”;(0.0%“(2L)”;——;@)

我需要确定它是2L还是1L。

一个简单的自定义项可能:

Function WhichOne(ByVal rng As Range) As String
    Application.Volatile
    If InStr(rng.NumberFormat, "1L") > 0 Then
        WhichOne = "1L"
    ElseIf InStr(rng.NumberFormat, "2L") > 0 Then
        WhichOne = "2L"
    Else
        WhichOne = "neither"
    End If
End Function
试试这个简单的自定义项

Function GetFormat(cell As Range) As String
Application.Volatile
If cell.NumberFormat = "General" Then GetFormat = "General": Exit Function
GetFormat = Split(Split(cell.NumberFormat, "%" & Chr(34) & "(")(1), ")")(0)
End Function

提取1L是什么意思?我希望能够显示1L,因为在另一个例子中,它看起来像0.0%“(2L)”;(0.0%“(2L)”;——;@)因此,我需要能够确定它是2L还是1L。我关于“常规”格式的评论更多的是为了指出,如果double
Split
返回错误,那么对于
GetFormat
,您没有“默认”值可返回。它可以是“常规”或“文本”,甚至是其他一些将返回错误的自定义数字格式。