convert a date format for over 500 rows using a For Next Loop

痴心易碎 提交于 2019-12-11 00:35:26

问题


I need to convert dates (up to last row) in column "C" from the existing format 24/01/2016 to 24.01.2016 The result has to be in date format.

My current code is:

LastRow9 = ws5.Cells(Rows.Count, "C").End(xlUp).Row
For X9 = 1 To LastRow9
searchvalue = Cells(X9, "C").Value
Answer = Split(searchvalue, "/")
ws5.Cells(X9, "A").Value = Answer
ws5.Cells(X9, "A").Value = Format(Answer, "dd.mm.yyyy")
Next X9

the answer i get is 30.12.1899 a bit off the mark


回答1:


Try changing the Range.NumberFormat property.

with ws5
    .range(.cells(1, "C"), .Cells(Rows.Count, "C").End(xlUp)).NumberFormat = "dd.mm.yyyy"
end with


来源:https://stackoverflow.com/questions/36660962/convert-a-date-format-for-over-500-rows-using-a-for-next-loop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!