问题
So, it is rather strange but this is what is happening. In my code I have the following line:
tbl_Input.Cells(46 + (l_position - 1) * L_SIZE_BA, 12) = tbl_Input.Cells(46 + (l_position - 2) * L_SIZE_BA, 12)
which is supposed to simply take the value of tbl_Input.Cells(a,b) and put it in tbl_Input.Cells(c,d). However, the value of Cells(a,b) is "06.01.2016" and when I run the code I get "07.01.2020".
If I take the text property like this, I get what I want correctly:
tbl_Input.Cells(46 + (l_position - 1) * L_SIZE_BA, 12) = tbl_Input.Cells(46 + (l_position - 2) * L_SIZE_BA, 12).Text
My question is like: Why do I get the 07.01.2020 in first place, when I am not writing .Text or .Value?
回答1:
About a year later, just checking the questions in StackOverflow, the answer of this one is really obvious - I was probably having ThisWorkbook.Date1904 = True.
It gives exactly 4 years and a day difference, whenever you are copying something.
This is how to replicate it:
Public Sub TestMe()
ThisWorkbook.Date1904 = True
Cells(1, 1) = Date
Cells(2, 1) = Cells(1, 1)
ThisWorkbook.Date1904 = False
End Sub
来源:https://stackoverflow.com/questions/36789271/vba-copying-dates-from-one-cell-to-another-strange-change