gpt4 book ai didi

excel - 维护 Excel 中的日期格式

转载 作者:行者123 更新时间:2023-12-02 16:50:43 28 4
gpt4 key购买 nike

我有一个包含三个组合框的表单,一个代表该月(可能的)31 天,第二个代表代表月份的 12 个数字,第三个代表与 future 五年相对应的年份值。

我将它们连接在一起形成一个日期

TheDay = CBDay.Value
TheMonth = CBMonth.Value
TheYear = CBYear.Value

thedate = TheDay + "/" + TheMonth + "/" + TheYear

因此,在澳大利亚,今天的日期将显示为 10/12/2015,这样效果很好。但是,当我将数据写入工作表时,即使写入数据的列的格式为“dd/mm/yy”样式的“日期”,日期也会持续转换为 12/10/2015

变量被声明为整数

有没有办法确保日期的值不会改变?

最佳答案

Excel 认为它对看起来像日期的字符串进行格式化是很聪明的。

尽可能使用日期序列号并采用您自己的格式

例如

Dim theDate As Date
theDate = DateSerial(TheYear, TheMonth, TheDay)

ActiveCell = theDate
ActiveCell.NumberFormat = "dd/mm/yyyy"
' or better yet, use an unambiguous date format
ActiveCell.NumberFormat = "dd mmm, yyyy"

关于excel - 维护 Excel 中的日期格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34195801/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com