Excel 使用宏用时间戳填充列

Excel 使用宏用时间戳填充列,excel,vba,Excel,Vba,我试图使用一个按钮将时间戳入一列单元格,每次按下按钮时,我希望它移动到下面的单元格,例如A1、A2、A3等 Sub RectangleRoundedCorners1_Click() With Range("A1") .Value = Now() .NumberFormat = "h:mm:ss AM/PM" End With End Sub 这会将当前时间戳添加到A1,每次都会替换内容,当excel识别A1已满时,我希望它在下一个单元格中打印。是否有某种+1循环我应该使用。我以前没有

我试图使用一个按钮将时间戳入一列单元格,每次按下按钮时,我希望它移动到下面的单元格,例如A1、A2、A3等

Sub RectangleRoundedCorners1_Click() 
With Range("A1") 
.Value = Now()

.NumberFormat = "h:mm:ss AM/PM" 
End With 
End Sub
这会将当前时间戳添加到A1,每次都会替换内容,当excel识别A1已满时,我希望它在下一个单元格中打印。是否有某种+1循环我应该使用。我以前没有用过VB


提前感谢。

每次运行宏时,您都需要确定
列A
中当前上次使用的行。然后使用
偏移量(1)
向下移动一行以删除新值

Sub RectangleRoundedCorners1_Click()

Dim LR As Long

With Sheets("Sheet1")
    LR = .Range("A" & .Rows.Count).End(xlUp).Offset(1).Row
    .Range("A" & LR).Value = Format(Now, "h:mm:ss AM/PM")
End With

End Sub
正如Darren所评论的那样

用于单元格(Rows.Count,1).End(xlUp).Offset(1)
。它将
A1
留空,因为它将从最后一行偏移一行,但将添加到A2、A3、A4等。
Sub RectangleRoundedCorners1_Click() 
With Cells(Rows.Count, 1).End(xlUp).Offset(1) 
.Value = Now()

.NumberFormat = "h:mm:ss AM/PM" 
End With 
End Sub