VBA_Excel将一个datevariables作为一个数字粘贴到一个单元格中

好的,我有这个小代码

If Trim(apriori) <> "" Then With Sheets(yolk).Range("1:1") Set Rng = .Find(apriori, .Cells(.Cells.Count), xlValues, xlWhole, xlByRows, _ xlNext, False) yolk = yolk - 1 'e = 1 If Not Rng Is Nothing Then 'Application.Goto Rng, True Rng.Offset(26, 0).Copy 'Worksheets("EXTRACTIONS").Range("B2").Offset(, e) some_date = Format(apriori, "dd/mmmm/yyyy") 'XX MsgBox some_date Worksheets("EXTRACTIONS").Range("B2").Offset(, e).Value = some_date 'XX Worksheets("EXTRACTIONS").Range("B3").Offset(, e).PasteSpecial xlPasteValues 'EDIT e = e + 1 'activeCell kane offset ekei pou theloume 'prwta offset theloume to address pou tha kanei to offset 'timy = ActiveCell.Address Else MsgBox "Nothing found" End If End With End If 

aprioridate value是美式格式的date value ,我想要的只是将其转换为日历查看日历的方式,例如:

12/31/2010 to 31/December/2010

所以我使用

format(apriori, "dd/mmmm/yyyy")

它做的工作,我有date,因为我希望她在msgbox some_date

但是,一旦我尝试将值粘贴到单元格

 Worksheets("EXTRACTIONS").Range("B2").Offset(, e).Value = some_date 

该单元格填充数字(!!!!),如41,274或41,679 …..(?)

我如何纠正我的VBA代码中的这个错误?

你应该改变你的单元格的数字格式 ,如下所示:

 Dim some_date As Date some_date = Now With Worksheets("EXTRACTIONS").Range("B2").Offset(, e) .NumberFormat = "dd/mmmm/yyyy" .Value = some_date End With