VBA,日期格式问题 [英] VBA, Date formatting issue

查看:144
本文介绍了VBA,日期格式问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个代码

1)比较X列到Y列的日期.

1) compares dates from Col X to Col Y.

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

2)paste dates to col Y if there is no match between columns.

第X列,我的格式如下

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

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

But when it pastes to column Y it goes,

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

如何格式化粘贴格式,使其变为dd/mm/yyyy.

How can I format my paste to go to 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

我尝试过的方法:更改单元格的格式

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

现在是X列的正确格式.

which is now the correct format for column X.

但这会粘贴到Y列中:

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

推荐答案

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

Use dd/MM/yyyy as cell format. Lowercase m stands for minutes, uppercase M for months.

这篇关于VBA,日期格式问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆