【问题标题】:Excel vba how to disallow Excel converting a month name with number into date? [duplicate]Excel vba如何禁止Excel将带有数字的月份名称转换为日期? [复制]
【发布时间】:2022-02-04 00:57:46
【问题描述】:
Sub test1()
MonthYear = MonthName(Right(2009, 2)) & " " & Left(2009, 2) 'locals window show "September 20"
Range("A1").Value = MonthYear '20-Sep is shown in cell A1 where the formula box is 20-09-2022
Range("A1").Value = "'" & MonthYear '---> my solution for the time being
End Sub

我想要的是在单元格 A1 中显示 September 20(就像在本地窗口中一样),作为文本而不是日期。

到目前为止我已经尝试过:

Sub test2()
MonthYear = "01-" & MonthName(Right(2009, 2)) & "-20" & Left(2009, 2) 'locals window show "01-September-2020"

Range("A1").Value = MonthYear '01-Sep-20 is shown in cell A1 where the formula box is 01-09-2020

Range("A2").Value = Format(MonthYear, "mmmm yy") 'AGAIN, 20-Sep is shown in cell A1 where the formula box is 20-09-2022

Range("A1").NumberFormat = "mmmm yy" 'another solution for the time being
End Sub

我的问题:
我该如何编写代码,以便将结果作为文本直接放入单元格中 September 20

任何形式的帮助都将不胜感激。
提前谢谢你????

【问题讨论】:

    标签: excel vba date


    【解决方案1】:

    首先应用文本格式:

    Range("A1").NumberFormat = "@"
    Range("A1").Value = MonthYear
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-09
      • 1970-01-01
      相关资源
      最近更新 更多