好的,我有这个小代码
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
价值apriori
是美国格式的date value
,我想要的是将其转换为日期查看日历的方式,例如:
12/31/2010 to 31/December/2010
所以我用
format(apriori, "dd/mmmm/yyyy")
它完成了这项工作,我有了日期,因为我希望她在msgbox some_date
但是,一旦我尝试使用
将值粘贴到单元格Worksheets("EXTRACTIONS").Range("B2").Offset(, e).Value = some_date
该单元格中填充了数字(!!!!),如41,274或41,679 ......(?)
如何在VBA
代码中更正此错误?
答案 0 :(得分:2)
您应该更改单元格的数字格式,如下所示:
Dim some_date As Date
some_date = Now
With Worksheets("EXTRACTIONS").Range("B2").Offset(, e)
.NumberFormat = "dd/mmmm/yyyy"
.Value = some_date
End With