0

我有以下代码。但是,我在单元格中发现输出(即 SEP08)在单元格中转换为 Sep-08。我怎样才能在没有日期格式的 Excel 电子表格中显示 SEP08?

Dim StartMonth As String
Select Case Month(EarliestDate)
    Case "1"
        StartMonth = "JAN" & Right(Year(EarliestDate), 2)
    Case "2"
        StartMonth = "FEB" & Right(Year(EarliestDate), 2)
    Case "3"
        StartMonth = "MAR" & Right(Year(EarliestDate), 2)
    Case "4"
        StartMonth = "APR" & Right(Year(EarliestDate), 2)
    Case "5"
        StartMonth = "MAY" & Right(Year(EarliestDate), 2)
    Case "6"
        StartMonth = "JUN" & Right(Year(EarliestDate), 2)
    Case "7"
        StartMonth = "JUL" & Right(Year(EarliestDate), 2)
    Case "8"
        StartMonth = "AUG" & Right(Year(EarliestDate), 2)
    Case "9"
        StartMonth = "SEP" & Right(Year(EarliestDate), 2)
    Case "10"
        StartMonth = "OCT" & Right(Year(EarliestDate), 2)
    Case "11"
        StartMonth = "NOV" & Right(Year(EarliestDate), 2)
    Case "12"
        StartMonth = "DEC" & Right(Year(EarliestDate), 2)
    End Select

ActiveCell.FormulaR1C1 = StartMonth
4

2 回答 2

1

在字符串前面加上一个反引号,如下所示:`SEP08

或者,要设置大量单元格,请使用单元格格式(通过选择范围并键入 CTRL-1 可用)并在数字选项卡上选择文本格式。

于 2013-05-11T04:03:42.030 回答
0

您应该使用数字格式将单元格设置为文本@

ActiveCell.NumberFormat ="@"
ActiveCell.FormulaR1C1 = StartMonth
于 2013-05-12T06:43:51.033 回答