使用VBA向excel添加时间戳

使用VBA向excel添加时间戳,excel,vba,Excel,Vba,这段代码从一张纸上复制值,并在第一个空列的另一张纸上通过它,现在每当我按下按钮时,我需要以下程序以同样的方式工作,除了我需要时间戳,然后是复制的值 Sub Button2_Click() Dim source As Worksheet Dim destination As Worksheet Dim source1 As Worksheet Dim destination1 As Worksheet Dim emptyColumn As Long Set source = Sheets(&q

这段代码从一张纸上复制值,并在第一个空列的另一张纸上通过它,现在每当我按下按钮时,我需要以下程序以同样的方式工作,除了我需要时间戳,然后是复制的值

Sub Button2_Click()

Dim source As Worksheet
Dim destination As Worksheet
Dim source1 As Worksheet
Dim destination1 As Worksheet
Dim emptyColumn As Long

Set source = Sheets("Input for Radar")
Set destination = Sheets("Sheet1")
Set source1 = Sheets("Input for Radar")
Set destination1 = Sheets("Sheet2")

If WorksheetFunction.CountA(destination.Columns(1)) Then
    emptyColumn = 1
Else
    emptyColumn = destination.Cells(1, destination.Columns.Count).End(xlToLeft).Column + 1
End If

destination.Cells(1, emptyColumn).Resize(100, 1).Value = source.Range("s4:s100").Value

If WorksheetFunction.CountA(destination1.Columns(1)) Then
    emptyColumn = 1
Else
    emptyColumn = destination1.Cells(1, destination1.Columns.Count).End(xlToLeft).Column + 1
End If

destination1.Cells(1, emptyColumn).Resize(100, 1).Value = source1.Range("ah4:ah100").Value
端接头


这是一个用于日期时间戳的函数

Private Function TimeInMS() As String
    Dim TimeNow As Double: TimeNow = Timer
    TimeInMS = Format(Date, "dd/mm/yyyy ") & Format(DateAdd("s", TimeNow, 0), "hh:mm:ss.") & Right(Format(TimeNow, "#0.00"), 2)
End Function
NOW()是获取时间戳的简单方法