gpt4 book ai didi

VBA,日期格式问题

转载 作者:行者123 更新时间:2023-12-03 00:19:02 25 4
gpt4 key购买 nike

我有一个代码

1) 比较从 Col X 到 Col Y 的日期。

2) 如果列之间不匹配,则将日期粘贴到 Y 列。

第 X 列我的格式如下

08/15/2013
09/12/2013
10/03/2013

但是当它粘贴到 Y 列时,它就会消失,

15/08/2013
12/09/2013
03/10/2013

如何格式化我的粘贴以转到 dd/mm/yyyy。

添加了更多代码来显示数组:

   ReDim PasteArr(1 To 1, 1 To 6)
subcount = 1

For Cell1 = 1 To UBound(DataArr(), 1)
For Each Cell2 In BusDates()
If DataArr(Cell1, 1) Like Cell2 Then
Matched = True
Exit For 'if it matches it will exit
ElseIf Cell2 Like BusDates(UBound(BusDates), 1) Then 'if it gets to the end, it's truly unique and needs to be added

For index = 1 To 6
PasteArr(subcount, index) = DataArr(Cell1, index)
Next index

subcount = subcount + 1

PasteArr = Application.Transpose(PasteArr)
ReDim Preserve PasteArr(1 To 6, 1 To subcount)
PasteArr = Application.Transpose(PasteArr)

Matched = False

End If
Next Cell2

If Matched = False Then
BusDates = Application.Transpose(BusDates)
ReDim Preserve BusDates(1 To UBound(BusDates) + 1)
BusDates = Application.Transpose(BusDates)
BusDates(UBound(BusDates), 1) = DataArr(Cell1, 1)
End If

Next Cell1
Worksheets("stacks").Range("M" & LastRow + 1 & ":" & Cells(LastRow + UBound(PasteArr, 1) - 1, 18).Address).Value = PasteArr

我尝试过的操作:更改单元格格式

enter image description here

15/08/2013
12/09/2013
03/10/2013

现在这是 X 列的正确格式。

但这将粘贴到 Y 列中:

enter image description here

这是

15/08/2013 - correct
09/12/2013 - incorrect
10/03/2013 - incorrect.

最佳答案

使用dd/MM/yyyy作为单元格格式。小写 m 代表分钟,大写 M 代表月。

关于VBA,日期格式问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52655007/

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