代码之家  ›  专栏  ›  技术社区  ›  adam

打印到单元格时,将类似日期的字符串保留为文本

  •  0
  • adam  · 技术社区  · 7 年前

    我得到了一些如下的值:

        A
    1   DEC 2018
    2   NOV 2018
    3   OCT 2018
    4   SEP 2018
    5   Q119 SGX
    6   Q120 SGX
    7   Q219 SGX
    

    前四个是字符串格式。

        A
    1   Dec-18
    2   Nov-18
    3   Oct-18
    4   Sep-18
    5   Q119 SGX
    6   Q120 SGX
    7   Q219 SGX
    

    我试过了 Dim arrOuput() as String

    2 回复  |  直到 7 年前
        1
  •  2
  •   SpaghettiCode    7 年前

    尝试将其与 ' 就像在GUI中一样。

    Sub preserveStringFormat()
    
        Dim strDate As String
    
        strDate = "DEC 2018"
    
        range("A1").Value = "'" & strDate
    
        MsgBox "alright!"
    
    End Sub
    

    希望有帮助!

        2
  •  1
  •   user4039065 user4039065    7 年前

    将目的地号码格式设置为文本(例如。 "@"

        With Worksheets("sheet7")
            With .Range(.Cells(2, "A"), .Cells(.Rows.Count, "A").End(xlUp))
                Debug.Print .Address(0, 0)
                .Offset(0, 1).NumberFormat = "@"
                .Offset(0, 1) = .Value2
            End With
        End With
    
    推荐文章