“ dd / mm / yyyy”通过VBA在Excel中使用日期格式 [英] "dd/mm/yyyy" date format in excel through vba

查看:229
本文介绍了“ dd / mm / yyyy”通过VBA在Excel中使用日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过excel-vba在excel表中以 dd / mm / yyyy格式编写日期。我使用 Cells(1,1).Value = Format(StartDate, dd / mm / yyyy)实现了。并且我的单元格值显示为 30/04/2014 ,这很好.....

I am trying to write a date in "dd/mm/yyyy" format in excel sheet thru excel-vba. I achieved it using Cells(1, 1).Value = Format(StartDate, "dd/mm/yyyy"). and my cell value comes out to be 30/04/2014, which is good.....

但是存在一些奇怪的问题...
因为我必须每次将startDate加1来迭代整个月,所以下一个值是 1/5/2014 代替 01/05/2014 直到每个月12日 12/5/2014 和从13日开始,月份再次变为两位数 13/05/2014 ....

But there is some weird problem... Since I have to iterate the startDate for whole month by everytime adding it by 1, so the next value comes out to be 1/5/2014 instead of 01/05/2014 until 12th of each month 12/5/2014 and from 13th, the month is again changing to two digits 13/05/2014....

我想要全部用两位数表示,因为我必须使用Range.Find方法再次搜索这些日期,在该方法中,我通过fromat传递 dd / mm / yyyy值。

I want it all in two digits as I have to again search for these dates using Range.Find method, in which I am passing value with "dd/mm/yyyy" fromat.

推荐答案

我明白了


Cells(1,1).Value = StartDate

Cells(1,1).NumberFormat = dd / mm / yyyy

Cells(1, 1).Value = StartDate
Cells(1, 1).NumberFormat = "dd/mm/yyyy"

基本上,我需要设置单元格格式,而不是设置日期。

Basically, I need to set the cell format, instead of setting the date.

这篇关于“ dd / mm / yyyy”通过VBA在Excel中使用日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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