excel - 将日期写入单元格并更改日期格式
问题描述
我的 VBA 代码有一些问题。我得到了存储为的日期变量,dd/mm/yyyy
但是当我将日期写入特定单元格时,格式更改mm/dd/yyyy
为和年份。
编码:
Sheets("report_orders").Select
Range("A1").Value = customerName
Range("A2").Value = "äæîðä " & orderID
Range("A3").Value = "äæîðä ì÷åç " & orderPo
'Range("B2").Value = orderDate
Range("B2").Value = Day(orderDate) & "/" & Month(orderDate) & "/" & Year(orderDate)
Debug.Print "year " & Year(orderDate)
Debug.Print "month " & Month(orderDate)
Debug.Print "day " & Day(orderDate)
但结果是:
解决方案
将日期放入单元格时,可以使用.NumberFormat
. 确保在输入值之前格式化单元格。例如
Range("B2").NumberFormat = "mm/dd/yyyy"
Range("B2").Value = orderDate
您可以阅读有关Range.NumberFormat 属性 (Excel).NumberFormat
的更多信息
推荐阅读
- node.js - '@' SyntaxError: 无效或意外的令牌
- r - r中的多次模拟
- wordpress - 显示特定类别并由管理员管理
- apache-kafka - SerializationException:IntegerDeserializer 接收的数据大小不是 4
- python - 如何在 QWebEnginePage-pyqt5 中使用 POST 方法打开 URL
- java - 背景图像会降低 recyclerview 的性能
- android - 如何使用 ToggleButton 从回收器视图适配器进行网络调用
- datatable - DataTable从聚合物中的vaadin-date-picker绘制日期范围
- dialogflow-es - 是否可以偏离对话流程并回到 DF 中的原始流程
- pandas - 如何从数据透视表中进行加权字数统计