简体   繁体   English

VBA,粘贴数组时的NumberFormat

[英]VBA, NumberFormat when pasting an array

I have the following vba code, but I want to paste it giving the format of dd-mm-yyyy.我有以下 vba 代码,但我想粘贴它,给出 dd-mm-yyyy 的格式。

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

I've tried:我试过了:

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

I am unsure on the format of this.我不确定这个的格式。 Where do I put numberformat?我在哪里放置数字格式?

on a different line, two actions:在另一条线上,有两个动作:

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"

But we can shorten it a little with With and Resize但是我们可以用WithResize把它缩短一点

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM