VBA,粘贴数组时使用NumberFormat

时间:2018-10-09 18:48:16

标签: excel vba excel-vba

我有以下vba代码,但我想将其粘贴为dd-mm-yyyy格式。

Worksheets("stack").Range("M" & LastRowM + 1 & ":" & Cells(LastRowM + UBound(PasteArr, 1) - 1, 18).Address).Value = PasteArr

我尝试过:

   Worksheets("stack").Range("M" & LastRowM + 1 & ":" & Cells(LastRowM + UBound(PasteArr, 1) - 1, 18).Address).Value = PasteArr.Numberformat = ('dd-mm-yyyy')

我不确定此格式。我在哪里放数字格式?

1 个答案:

答案 0 :(得分:4)

在另一行上,执行两个操作:

Worksheets("stack").Range("M" & LastRowM + 1 & ":" & Cells(LastRowM + UBound(PasteArr, 1) - 1, 18).Address).Value = PasteArr
Worksheets("stack").Range("M" & LastRowM + 1 & ":" & Cells(LastRowM + UBound(PasteArr, 1) - 1, 18).Address).NumberFormat = "dd-mm-yyyy"

但是我们可以使用WithResize

将其缩短一点
With Worksheets("stack").Range("M" & LastRowM + 1).resize(Ubound(pasteArr,1),18)
    .Value = PasteArr
    .NumberFormat = "dd-mm-yyyy"
End With