0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Excel VBA 活取随机日期

Posted at

这个函数用于获取fstDate到lstDate之间的随机日期

Sub AUTO_CALENDAR()
    Dim fstDate As Date
    Dim lstDate As Date
    fstDate = #1/1/2023#
    lstDate = #12/31/2025#
    col = "K"
    For i = 2 To 10001
        Cells(i, col) = CStr(Format(Int(lstDate - fstDate + 1) * Rnd + fstDate, "yyyyMMdd"))
    Next i
End Sub

fstDate 是随机写入日期范围的初始日期值(包含)
lstDate 是随机写入日期范围的截至日期(包含)
for i 为需要写入数据的行号
col 是写入位置的列名

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?