【问题标题】:How can I obtain the displayed value instead of actual value in Excel?如何在 Excel 中获取显示值而不是实际值?
【发布时间】:2010-11-09 03:20:01
【问题描述】:

我有一个包含日期前的单元格。 “09 年 5 月 11 日” 当前显示为“11-MAY-09”。如何复制粘贴或使用 VBA 将字符串“11-MAY-09”放入其旁边的单元格(不是“05/11/09”)?

除了自己拼出日期片段之外,我无法弄清楚。

【问题讨论】:

    标签: excel vba date copy format


    【解决方案1】:
    Range("B1").Value = Range("A1").Text
    

    使用单元格的 .text 而不是 .value 修饰符将复制文本格式而不是原始日期。

    查克

    【讨论】:

      【解决方案2】:

      我相信您可以使用 TEXT 函数来格式化您喜欢的日期值。

      “dd-mmm-yy”的格式字符串会将“05/11/09”格式化为“11-MAY-09”。

      【讨论】:

        【解决方案3】:

        使用格式化功能。

        Format("5/11/2009", "DD-MMM-YY")
        

        这将返回:

        11-May-09
        

        如果情况很重要:

        UCase(Format("5/11/2009", "DD-MMM-YY"))
        

        返回:

        11-MAY-09
        

        【讨论】:

          【解决方案4】:

          “相同的答案,但功能不同(对我有用):

          Public Function DisplayText(ByVal pRange As Range) As String  
            DisplayText = pRange.Text  
          End Function  
          

          只需使用=DisplayText(A1)。如果您更改单元格格式,此函数将返回显示的文本"

          • cc: alvaroc

          How can I get the displayed value of a cell in MS Excel ( for text that was converted to dates)?

          【讨论】:

            【解决方案5】:

            试试这个:

            Sub FormattedText()
                Dim r As Range
            
                On Error Resume Next
                Set r = Application.InputBox(prompt:="Select cell", Type:=8)
                If r.Count <> 1 Or r Is Nothing Then
                    Exit Sub
                End If
                On Error GoTo 0
            
                ActiveCell = "'" & r.Text
            
            End Sub
            

            它将所选单元格的文本(提示)放入活动单元格中。

            【讨论】:

              【解决方案6】:

              您应该能够右键单击单元格并将格式设置为常规。这将允许您放入某些内容,而不会自动将其格式化为其他内容。

              为了避免复制和粘贴,您还需要先输入所需的日期,而不是格式化然后复制。

              【讨论】:

                【解决方案7】:

                在 VBA 中你可以这样做:

                Range("B2") = Range("A2")
                Range("B2").NumberFormat = "dd-mmm-yyyy hh:mm:ss" 'Date as 10-Jun-2005
                

                如果需要循环的话:

                Range("B" & i) = Range("A"& i)
                Range("B" & i).NumberFormat = "dd-mmm-yyyy hh:mm:ss" 'Date as 10-Jun-2005
                

                Another way to do it.

                【讨论】:

                  【解决方案8】:

                  技术含量低但非常简单的方法 - 将其粘贴到 Word 中,然后复制回 Excel!处理大文件可能需要一段时间,但是……但非常适合一次性使用!

                  【讨论】:

                    猜你喜欢
                    • 2012-02-09
                    • 2021-05-14
                    • 1970-01-01
                    • 1970-01-01
                    • 2022-11-17
                    • 1970-01-01
                    • 1970-01-01
                    • 1970-01-01
                    • 2018-10-10
                    相关资源
                    最近更新 更多