代码之家  ›  专栏  ›  技术社区  ›  Mario Palumbo

如果单元格格式为文本,则不计算公式

  •  0
  • Mario Palumbo  · 技术社区  · 6 年前

    我需要保持单元格的文本格式,同时确保Excel计算其中的公式。

    3 回复  |  直到 6 年前
        1
  •  1
  •   andy01q    6 年前

    在文本函数中嵌入excel公式。 你的职能 ,"@") https://support.office.com/en-us/article/text-function-20d5ac4d-7b94-49fd-bb38-93d29371225c 编辑:如果公式没有被计算,那么除了单元格格式之外,还有其他原因。

        2
  •  1
  •   Mario Palumbo    6 年前

    在图纸模块中:

    Option Explicit
    Private Busy As Boolean
    Private Sub Worksheet_Change(ByVal Target As Range)
        If Not Busy Then
            Busy = True
            If ActiveSheet.ProtectContents Then ActiveSheet.Protect UserInterfaceOnly:=True
            CalculateFormula Target.Row, Target.Column
            Busy = False
        End If
    End Sub
    

    在标准模块中:

    Option Explicit
    Sub CalculateFormula(Row As Long, Column As Long)
        Dim Format As String
        If Left(Cells(Row, Column).Value, 1) = "=" Then
            Format = Cells(Row, Column).NumberFormat
            Cells(Row, Column).NumberFormat = "General"
    On Error Resume Next
            Cells(Row, Column).FormulaLocal = Cells(Row, Column).Value
    On Error GoTo 0
            Cells(Row, Column).NumberFormat = Format
        End If
    End Sub
    
        3
  •  0
  •   Forward Ed    6 年前

    ISTEXT(A1) 其中A1是所讨论的单元格。它仍然会成为现实。

    为了使单元格的内容成为字符串,只需将公式与“”连接起来即可。

    =Your_Function&""
    
    =1+1&""