日期格式从D-M-Y更改为M-D-Y [英] Date format changes from D-M-Y to M-D-Y
问题描述
在一个csv文件中,我获得了一个变量 BookingDate
,其值为"8-9-2016".我想遍历Excel工作表以检查是否与该值匹配.
Out of a csv file, I obtain a variable BookingDate
with value "8-9-2016". I want to loop through an Excel sheet to check, if there is a match with that value.
我发现,当我想在VBA中使用它们时,从工作表中读取的值已更改.假设,我设置了一个变量 BookingDate2
并为其提供了一个这样的值:
I discovered, that the values I read from the sheet are changed, when I want to use them in VBA. Let's say, I set a variable BookingDate2
and give it a value like this:
LR = ThisWorkbook.Sheets("Sheetname").Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To LR
BookingDate2 = ThisWorkbook.Sheets("Boekingen AMS-IAD").Cells(i, 1).Value
然后我要检查,是否找到了这样的匹配项:
Then I want to check, if it found a match like this:
If (BookingDate = BookingDate2) Then
'Do something
BookingDate
的值为"8-9-2016",而 BookingDate2
的值应为"8-9-2016",但更改为"9"-8-2016".
BookingDate
has value "8-9-2016" and the value of BookingDate2
is supposed to be "8-9-2016", but is changed to "9-8-2016".
推荐答案
我已修复它!
我忘记了将变量变暗为Date.就像这样:
I forgot to Dim the variables to Date. It was like this:
Dim BookingDate As String
Dim BookingDate2 As String
但这必须是:
Dim BookingDate As Date
Dim BookingDate2 As Date
那对我有用.
这篇关于日期格式从D-M-Y更改为M-D-Y的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!